我正在使用具有许多不同库依赖项的gradle项目并使用新的清单合并.在我的
标签中,我将其设置为:
....
然而,我收到错误:
/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"' toelement 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 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 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 element at AndroidManifest.xml:26:5 to override
小智.. 210
像这样声明你的清单标题
然后,您可以向应用程序标记添加以下属性:
例如,我需要替换图标和标签.祝好运!
我刚刚经历了与tools:replace=...
OP所描述的相同的行为.
事实证明,tools:replace
清单合并被忽略的根本原因是这里描述的错误.它基本上意味着如果项目中有一个包含带有<application ...>
包含tools:ignore=...
属性的节点的清单的库,则可能tools:replace=...
会忽略主模块清单中的属性.
这里棘手的一点是,它可以发生,但不必.在我的例子中,我有两个库,库A具有tools:ignore=...
属性,库B具有要在相应清单中替换的tools:replace=...
属性以及主模块清单中的属性.如果B的清单在A的清单之前合并到主清单中,那么一切都按预期工作.在相反的合并顺序中出现错误.
这些合并发生的顺序似乎有点随机.在我的情况下,更改依赖项部分中的顺序build.gradle
没有任何效果,但改变了味道的名称.
因此,唯一可靠的解决方法似乎是解压缩导致库的问题,删除tools:ignore=...
标记(这应该没有问题,因为它只是lint的提示)并再次打包库.
并且投票支持修复错误的原因.
我的最终工作解决方案(突出显示示例代码中的tages):
xmlns:tools
在清单标记中添加该行
添加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"** >
像这样声明你的清单标题
<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" ../>
例如,我需要替换图标和标签.祝好运!
您可以替换Manifest应用程序标记中的那些:
<application tools:replace="android:icon, android:label, android:theme, android:name,android:allowBackup" android:allowBackup="false"...>
并将为你工作.
尝试重新排序gradle文件中的依赖项.我不得不将有问题的库从列表底部移到顶部,然后才能工作.
对我来说遗失的是:
xmlns:tools="http://schemas.android.com/tools"
例如:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.your.appid">
我修复了同样的问题.我的解决方案:
xmlns:tools="http://schemas.android.com/tools"
在清单标记中添加该行
添加tools:replace=..
清单标记
移动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"/>