Manifest merger failed : Attribute application@icon value=(@mipmap/ic_launcher) from AndroidManifest

来源:互联网 发布:手机健身软件 编辑:程序博客网 时间:2024/06/05 17:38

有问题欢迎加Q:1092417123

情况是这样子的,导入一个比较老的项目(两年前),它依赖于一个 Libraray,已经先导入了 library,现在导入项目的时候出了错

(1) Android Studio 目前提供将 SDK包成 .aar 档案格式的方式,此方式除了将 class 包入之外,也会将资源、图片等,都一起包入。而以前所使用的 .jar 只会将相关的 class 包入,所以在以前将资源文件一起导入有时候会出问题

(2) 所有的资源文件会被 merge 在一起,什么意思呢?就是如果你自己做的SDK中包了一個 layout 叫做 abc.xml,當有个 project 使用你的SDK,而且这个 project 也有一个 layout/abc.xml,在将你的 SDK include 到 project 以后,build 的过程中,SDK中的abc.xml會和 project 中的abc.xml合并(或是取代)。

(3) 因为(2)的原因,所有的 resource file name 或是 resource id 都记得加上 prefix 或是 postfix,用 darkwing_co_abc.xml 或是 abc_darkwing_co.xml 的方式命名。不会因为合并或取代造成未知的错误。

(4) 有时候在编译的时候,遇到 attribute 重复的情况会回报错误,eg:

Error:Execution failed for task ':app:processDebugManifest'.> Manifest merger failed : Attribute application@icon value=(@mipmap/ic_launcher) from AndroidManifest.xml:10:9-43is also present at [com.pnikosis:materialish-progress:1.0] AndroidManifest.xml:13:9-45 value=(@drawable/ic_launcher)Suggestion: add 'tools:replace="android:icon"' to element at AndroidManifest.xml:8:5-22:19 to override

这是因为 manifeast file 中某些 attribute 与 project 中的 minifeast 的 attribute 有重复,像是上面的例子,是说这两个地方都有 ic_launcher,所以编译器不知道用哪一个

这个时候可以指定下面的方式让编译器知道:
tools:replace=”android:icon,android:theme”

<?xml version="1.0" encoding="utf-8"?><manifest   xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    package="co.darkwing.bookingapp" >    <application        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme_darkwing_co"        tools:replace="android:icon,android:theme">        <activity            android:name=".MainActivity"            android:label="@string/app_name" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application></manifest>

注意, attribute 报错时候,什么报错就替换什么,我的 Theme 也报错了,替换之后无效,我就直接去掉一些Activity 的Theme,然后成功运行

PS:若同时还有 权限错误(写的位置没有错),可以先注释掉再编译,编译成功后再解开,再编译,我这样成功了,很无奈

0 0
原创粉丝点击