工具:取代Android清单中的replace

我正在使用具有许多不同库依赖项的gradle项目,并使用新的清单合并器。 在我的<application />标签中,我设置了它:

 <application tools:replace="android:icon, android:label, android:theme, android:name" android:name="com.example.myapp.MyApplcation" android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/application_name" android:logo="@drawable/logo_ab" android:theme="@style/AppTheme" > .... </application> 

但是我收到错误:

 /android/MyApp/app/src/main/AndroidManifest.xml:29:9 Error: Attribute application@icon value=(@drawable/ic_launcher) from AndroidManifest.xml:29:9 is also present at {Library Name} value=(@drawable/app_icon) Suggestion: add 'tools:replace="android:icon"' to <application> element at AndroidManifest.xml:26:5 to override /android/MyApp/app/src/main/AndroidManifest.xml:30:9 Error: Attribute application@label value=(@string/application_name) from AndroidManifest.xml:30:9 is also present at {Library Name} value=(@string/app_name) Suggestion: add 'tools:replace="android:label"' to <application> element at AndroidManifest.xml:26:5 to override /android/MyApp/app/src/main/AndroidManifest.xml:27:9 Error: Attribute application@name value=(com.example.myapp.MyApplication) from AndroidManifest.xml:27:9 is also present at {Another Library} Suggestion: add 'tools:replace="android:name"' to <application> element at AndroidManifest.xml:26:5 to override /android/MyApp/app/src/main/AndroidManifest.xml:32:9 Error: Attribute application@theme value=(@style/AppTheme) from AndroidManifest.xml:32:9 is also present at {Library Name} value=(@style/AppTheme) Suggestion: add 'tools:replace="android:theme"' to <application> element at AndroidManifest.xml:26:5 to override 

声明你的清单头像这样

 <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.yourpackage" xmlns:tools="http://schemas.android.com/tools"> 

比添加到您的应用程序标记以下属性:

 <application tools:replace="icon, label" ../> 

例如,我需要replace图标和标签。 祝你好运!

尝试在您的gradle文件中重新sorting依赖项。 我不得不从名单底部将违规图书馆移到顶部,然后才能正常工作。

我修正了同样的问题。 对我的解决scheme:

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

例:

  <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" tools:replace="allowBackup, label" android:allowBackup="false" android:label="@string/all_app_name"/> 

我刚刚经历了与OP描述的tools:replace=...相同的行为tools:replace=...

事实certificate, tools:replace的根本原因tools:replace被清单合并忽略是一个在这里描述的错误。 这基本上意味着,如果您的项目中包含一个包含具有包含tools:ignore=...属性的<application ...>节点的清单的库,则可能发生以下tools:replace=...属性你主模块的清单将被忽略。

这里棘手的一点是它可能发生,但不一定。 在我的情况下,我有两个库,库A的tools:ignore=...属性,库B的属性将被replace在各自的清单和tools:replace=...属性在主模块的清单。 如果B舱单在A舱单之前被合并到主舱单中,那么所有的一切都按预期工作。 在相反的合并顺序中出现错误。

这些合并的顺序似乎有些随意。 在我的情况下,改变build.gradle的依赖部分的build.gradle没有效果,但改变了它的名字。

所以,唯一可靠的解决方法似乎是解压缩导致库的问题,删除tools:ignore=...标记(这应该是没有问题的,因为它只是针对lint的提示)并再次打包库。

并投票修正错误的原因。

对我来说,最终的工作解决scheme(在示例代码中突出显示):

  1. 在清单标签中添加xmlns:tools
  2. 添加tools:replace应用程序标签

例:

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="pagination.yoga.com.tamiltv" **xmlns:tools="http://schemas.android.com/tools"** > <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" **tools:replace="android:icon,android:theme"** > 

固定它有确切的错误,只需添加此工具:replace =“android:icon,android:theme”

到您的清单中的应用程序标签,它工作得很好,

您可以replace您的Manifest application标记中的那些标记:

 <application ... tools:replace="android:label, android:icon, android:theme"/> 

并会为你工作。

说明

在您的gradle文件中使用这样的依赖/库,在其Manifest的应用程序标签中包含这些标签可能会产生这个问题,并将其replace到您的Manifest是解决scheme。

对我来说,缺less的一块是:

 <manifest xmlns:android="http://schemas.android.com/apk/res/android" --YOU NEED THIS LINE--> xmlns:tools="http://schemas.android.com/tools" package="com.your.appid">