根据这个doc,我们不再需要在 AndroidManifest.xml 中提供包名,而是在 build.gradle 中使用命名空间,我们可以在那里定义我们的包名。
package="org.sample.domain" found in source AndroidManifest.xml: C:\Users\user\Desktop\Projects\Sample\app\libs\sample\src\main\AndroidManifest.xml.
Setting the namespace via a source AndroidManifest.xml's package attribute is deprecated.
Please instead set the namespace (or testNamespace) in the module's build.gradle file, as described here: https://developer.android.com/studio/build/configure-app-module#set-namespace
This migration can be done automatically using the AGP Upgrade Assistant, please refer to https://developer.android.com/studio/build/agp-upgrade-assistant for more information.
但是在执行此操作后,Merged Manifest 选项卡显示错误,指出我没有提供包名称。我同时尝试了两者,但警告构建再次显示。
从清单中删除包元素并将其作为命名空间插入到 build.gradle(:app) 中:
{android
...
...
namespace 'your.package.name'
}
从
package="..."
模块的 <manifest>
文件中的 AndroidManifest.xml
元素中删除 app
属性,并将其添加到应用程序模块 build.gradle,即 build.gradle(:app)
和 namespace
android {
...
namespace 'com.your.unique.package.name'
}
注意: 如果你的项目是多模块的,你必须对每个其他模块执行此操作。