【问题标题】:Manifest merger failed error清单合并失败错误
【发布时间】:2015-03-21 15:41:33
【问题描述】:

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

这些属性定义都不起作用。我做错了什么?

【问题讨论】:

    标签: java android android-studio gradle android-manifest


    【解决方案1】:

    试试这个:

    将此添加到&lt;manifest/&gt;

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

    将此添加到&lt;application/&gt;

    tools:node="replace"
    

    基于this,它应该覆盖所有元素。 "用带注释的声明替换较低优先级的声明。"

    【讨论】:

    • 非常感谢。出于某种原因tools:replace 拒绝工作,但这有效(虽然可能有点急切)
    • 这不适用于我在 AS 1.3.2 中使用 gradle 插件 1.2.3 或 1.3.0
    • 此问题是由于 Manifest 文件或 build.gradle 文件中的问题。你可以查看我的帖子wordpress.com/post/dhingrakimmi.wordpress.com/23
    • 在我的情况下缺少字符串
    • @kayvan after using(tools:node="replace") 我在 firebase 设置中崩溃了
    【解决方案2】:

    背景

    合并清单文件时,与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" 定义添加到&lt;manifest&gt; 节点,并将tools:replace="label" 定义到&lt;application&gt;节点。

    这是一个示例 - 在主应用程序的 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"

    【讨论】:

    • 这不适用于我在 AS 1.3.2 中使用 gradle 插件 1.2.3 或 1.3.0
    • 这在 1.4 中对我有用(顺便说一句,描述很好)
    • 图书馆的应用清单中是否需要/需要 android:label 的具体原因?
    • @BlažŠnuderl 我没有尝试过没有这个,因为它是应用程序内活动中使用(并呈现给用户)标签的基础。见:developer.android.com/guide/topics/manifest/…
    • 为什么清单文件会被合并?我在正常构建后开始出现此错误,除了编辑 java 源文件之外我什至没有做任何事情!
    【解决方案3】:

    如果您像我一样幸运的话,您可以通过一种 hacky 变通方法手动解决问题。

    AAR 文件只是带有 .aar 扩展名的 .zip 文件。就我而言,我解压缩了 .aar,从库的 AndroidManifest.xml 中删除了有问题的 android:label,然后使用 .aar 扩展名重新归档了剩余的文件,一切似乎都可以与新的 .aar 完美配合。

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

    【讨论】:

    • 这对我有用。所有其他解决方案都不起作用
    【解决方案4】:

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

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

    Example here

    【讨论】:

      【解决方案5】:

      我刚刚删除了

      android:label="@string/app_name

      来自manifest file,它成功了!

      【讨论】:

      • 这是有效的,但它也会更改应用程序的显示名称。
      【解决方案6】:

      我从

      修改了清单文件
      <?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 被父应用程序的标签替换了。

      【讨论】:

        【解决方案7】:

        我也面临同样的问题,经过大量研究找到了灵魂

        1. 您的最小 sdk 版本应该与您正在使用的模块相同 例如:您的模块 min sdk 版本为 14,您的应用程序 min sdk 版本为 9 应该是一样的。
        2. 如果您的应用程序和模块的构建版本不同。同样应该是一样的

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

        1. 没有重复,例如在清单文件中添加两次相同的权限,两次提及相同的活动
        2. 如果您从项目中删除了任何活动,请将其从清单文件中删除
        3. 有时是因为清单文件的标签、图标等标签 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

        【讨论】:

          【解决方案8】:

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2020-01-01
            • 2019-11-19
            相关资源
            最近更新 更多