我正在将当前项目的大型应用程序迁移到 Android Studio 和 Gradle 中。我目前陷入以下问题:
Error:(87, 9) Execution failed for task ':App:processDebugManifest'.
> Manifest merger failed : Attribute application@label value=(@string/app_label) from AndroidManifest.xml:87:9
is also present at ANDROID_APPLICATION:Library:unspecified:9:18 value=(@string/app_name)
Suggestion: add 'tools:replace="android:label"' to <application> element at AndroidManifest.xml:82:5 to override
我尝试将以下属性添加到主
AndroidManifest.xml
文件中:
tools:replace="android:label, *App Name*"
tools:replace="android:label, @string/app_label"
tools:replace="android:label"
这些属性定义都不起作用。我做错了什么?
尝试一下:
将此添加到
<manifest/>
xmlns:tools="http://schemas.android.com/tools"
将此添加到
<application/>
tools:node="replace"
基于this,它应该覆盖所有元素。 “用带注释的声明替换优先级较低的声明。”
合并清单文件时,与
label
属性存在冲突。
一般来说,有三种类型的清单文件需要合并到单个生成的应用程序清单中,此处按优先顺序排列:
冲突可以通过以下两种方式之一解决:-
从库(或较低级别)清单文件中删除冲突的属性。
在这种情况下,
ANDROID_APPLICATION:Library:unspecified:9:18 value=(@string/app_name)
定义的@string/app_name
值与主应用程序中的值不同。因此,如果不需要,请将其删除 - 只需从库文件的 android:label="@string/app_name"
文件中删除 AndroidManifest.xml
即可。
有几个特殊属性标记(在工具命名空间中)可用于表达如何解决冲突的具体决定。
在这种情况下,要显式地使主应用程序的
android:label
覆盖任何其他(例如库文件)应用程序标签,请将 xmlns:tools="http://schemas.android.com/tools"
定义添加到 <manifest>
节点,并将 tools:replace="label"
添加到 <application>
节点。
这是一个示例 - 在主应用程序的
AndroidManifest.xml
文件中使用它:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.myapp"
xmlns:tools="http://schemas.android.com/tools">
<application
android:label="@string/app_name"
tools:replace="label"/>
</manifest>
此方法也适用于任何其他冲突的属性;例如,如果
icon
属性也存在冲突,则可以将其更改为 tools:replace="label, icon"
。
如果您像我一样幸运,您可以通过一种巧妙的解决方法手动解决问题。
AAR 文件只是带有 .aar 扩展名的 .zip 文件。就我而言,我解压了 .aar,从库的
android:label
中删除了有问题的 AndroidManifest.xml
,然后使用 .aar 扩展名重新归档了剩余的文件,一切似乎都与新的 .aar 完美配合。
我解决了同样的问题。我的解决方案:
xmlns:tools="http://schemas.android.com/tools"
行tools:replace=..
android:label=...
移至清单标签中我刚刚删除了
android:label="@string/app_name
来自
manifest file
,它成功了!
我修改了清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example">
<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true">
<activity android:name=".SomeActivity"/>
</application>
</manifest>
至
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true"
tools:replace="android:label">
<activity android:name=".SomeActivity"/>
</application>
</manifest>
现在
android:label
已被父应用程序中的标签替换。
我也面临同样的问题,经过大量研究找到了解决办法
- 您的最小 sdk 版本应与您正在使用的模块相同 例如:您的模块最小 sdk 版本是 14,您的应用程序最小 sdk 版本是 9 应该是一样的。
- 如果您的应用程序和模块的构建版本不同。再次应该是一样的
简而言之,您的应用程序 build.gradle 文件和清单应该具有相同的配置
- 不存在重复,例如在清单文件中添加两次相同的权限,两次提及相同的活动
- 如果您从项目中删除了任何活动,请将其从清单文件中删除
- 有时是因为清单文件的标签、图标等标签 a) 在清单标记中添加 xmlns:tools 行 b) 在应用程序标签中添加tools:replace=或tools:ignore= 示例
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.slinfy.ikharelimiteduk"
xmlns:tools="http://schemas.android.com/tools"
android:versionCode="1"
android:versionName="1.0" >
<application
tools:replace="icon, label"
android:label="myApp"
android:name="com.example.MyApplication"
android:allowBackup="true"
android:hardwareAccelerated="false"
android:icon="@drawable/ic_launcher"
android:theme="@style/Theme.AppCompat" >
</application>
</manifest>
通过考虑这些要点,您将摆脱这个明显的合并失败问题 查看我的帖子:此问题是由于 Manifest 文件或 build.gradle 文件中的问题造成的。你可以查看我的帖子 https://wordpress.com/post/dhingrakimmi.wordpress.com/23
尝试添加
android.useAndroidX=true
和 android.enableJetifier=true
在 gradle.properties
文件中。
它帮助我解决了我的问题。
我也遇到了同样的问题。就我而言,AndroidManifest.xml 文件中的
android:label
为空。然后我改成如下
android:label="@string/app_name
也许这个简单的解决方案会对某人有所帮助。谢谢。
请帮助我的项目解决方案清单合并失败:来自 [com.google.android.gms:play-services-ads-lite:22.6.0] 的属性 property#android.adservices.AD_SERVICES_CONFIG@resource value=(@xml/gma_ad_services_config) AndroidManifest.xml:92:13-59 也存在于 [com.google.android.gms:play-services-measurement-api:21.5.0] AndroidManifest.xml:32:13-58 value=(@xml/ga_ad_services_config)。 建议:将 'tools:replace="android:resource"' 添加到 AndroidManifest.xml 的元素中以进行覆盖。