清单合并失败错误

Manifest merger failed error

我正在将我当前的项目大型应用程序移动到 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"

None 这些属性定义有效。我做错了什么?

试一试:

将此添加到 <manifest/>

xmlns:tools="http://schemas.android.com/tools"

将此添加到 <application/>

tools:node="replace"

基于this,它应该覆盖所有元素。 "Replace the lower priority declaration with the annotated one."

背景

合并清单文件时,与 label 属性发生冲突。

一般来说,there are three types 个清单文件需要合并到一个生成的应用程序清单中,此处按优先顺序排列:

  1. 产品风格和构建类型特定的清单文件。
  2. 应用程序的主清单文件。
  3. 库清单文件。

决议

可以通过以下两种方式之一解决冲突:-

删除冲突标签

从库(或较低级别)清单文件中删除冲突的属性。

在这种情况下,ANDROID_APPLICATION:Library:unspecified:9:18 value=(@string/app_name) 定义了一个与主应用程序中不同的 @string/app_name 值。因此,如果不需要,则将其删除——只需从库文件的 AndroidManifest.xml 文件中删除 android:label="@string/app_name"

添加一个属性以允许自动解决冲突

several special attribute markers(在工具命名空间中)可用于表达如何解决冲突的特定决定。

在这种情况下,要明确导致主应用程序的 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".

如果你像我一样幸运的话,你可以通过一个 hacky work-around 手动解决这个问题。

A​​AR 文件只是扩展名为 .aar 的 .zip 文件。在我的例子中,我解压缩了 .aar,从库的 AndroidManifest.xml 中删除了有问题的 android:label,然后用 .aar 扩展名重新归档了剩余的文件,一切似乎都与新的 .aar 完美配合。

仅供参考,this appears to be a known bug in the android gradle plugin

我也遇到了同样的问题,经过大量研究找到了答案

  1. your min sdk version should be same as of the modules you are using eg: your module min sdk version is 14 and your app min sdk version is 9 It should be same.
  2. If build version of your app and modules not same. Again it should same

简而言之,您的应用 build.gradle 文件和清单应该具有相同的配置

  1. There's no duplicacy like same permissions added in manifest file twice, same activity mention twice
  2. If you have delete any activity from your project, delete it from your manifest file as well
  3. Sometimes its becuase of label, icon etc tag of manifest file a) add the xmlns:tools line in the manifest tag b) add tools:replace= or tools:ignore=in the application tag Example
   <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>

考虑到这些要点,您将摆脱这个清单合并失败的问题 检查我的 post:这个问题是由于清单文件或 build.gradle 文件中的问题。你可以查看我的 post https://wordpress.com/post/dhingrakimmi.wordpress.com/23

我解决了同样的问题。我的解决方案:

  1. 在清单标签中添加 xmlns:tools="http://schemas.android.com/tools"
  2. 在清单标签中添加tools:replace=..
  3. 在清单标签中移动 android:label=...

Example here

我刚刚删除了

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 被父应用程序中的标签所取代。

尝试添加 android.useAndroidX=trueandroid.enableJetifier=truegradle.properties 文件中。 它帮助我解决了我的问题。

我遇到了同样的问题。在我的例子中,android:label 在 AndroidManifest.xml 文件中是空的。然后我把它改成下面

android:label="@string/app_name

也许这个简单的解决方案会对某人有所帮助。谢谢。