删除命名空间的包名称时发生 Android 清单合并错误

Bit*_*EVS 35 android android-manifest android-studio android-gradle-plugin

根据此文档,我们不再需要在 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.
Run Code Online (Sandbox Code Playgroud)

但执行此操作后,“合并清单”选项卡会显示错误,指出我没有提供包名称。我同时尝试了两者,但警告版本再次显示。

在此输入图像描述

Rob*_*bin 41

从模块文件中的元素中删除package="com.your.unique.package.name"属性<manifest>AndroidManifest.xmlapp

将其添加到应用程序模块 build.gradle 即build.gradle(:app)使用namespace

android {
     ...
     namespace 'com.your.unique.package.name'
}
Run Code Online (Sandbox Code Playgroud)

注意:如果您的项目是多模块,则必须对每个其他模块执行此操作。


gue*_*r47 18

从清单中删除包元素并将其插入 \xc2\xa7build.gradle\xc2\xa7(:app) 作为命名空间:

\n
android {\n    ...\n    ...\n    namespace 'your.package.name'\n}\n
Run Code Online (Sandbox Code Playgroud)\n