AndroidManifest冲突如何解决
在我们引入第三方依赖的时候很可能有些不规范,在manifest中存在他自己的一些配置,就会导致在我们编译的时候不通过:Manifest merger failed with multiple errors, see logs
点开信息查看
java.lang.RuntimeException: Manifest merger failed with multiple errors, see logs
at com.android.builder.core.AndroidBuilder.mergeManifestsForApplication(AndroidBuilder.java:524)
at com.android.build.gradle.tasks.MergeManifests.doFullTaskAction(MergeManifests.java:143)
at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.java:106)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
这一堆信息完全无法查看是哪里冲突了,只好看依赖里的源码
// 三方依赖的manifest
<application android:allowBackup="true" android:label="@string/app_name"
android:icon="@drawable/ic_launcher" android:theme="@style/AppTheme">
</application>
// 自己的manifest
<application
android:name=".SampleApp"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
比较后发现有出入,我们就可以使用代码替换掉tools:replace="icon"
,发现又有一个错误
Manifest merger failed : uses-sdk:minSdkVersion 14 cannot be smaller than version 15 declared in library [com.lib:lib:0.5.3] C:\Users\EDZ\.gradle\caches\transforms-1\files-1.1\lib-0.5.3.aar\64c72f5f317fee31b6a468c651e319e1\AndroidManifest.xml as the library might be using APIs not available in 14
Suggestion: use a compatible library with a minSdk of at most 14,
or increase this project's minSdk version to at least 15,
or use tools:overrideLibrary="com.lib" to force usage (may lead to runtime failures)
这里可以很清晰的看到提示最低版本不一致,在manifest中添加<uses-sdk tools:overrideLibrary="com.lib"/>
就能很好的解决了
整个manifest文件
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.sample">
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk tools:overrideLibrary="com.lib, com.lib2"/>
<application
android:name=".SampleApp"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:replace="icon,label"> // 这里可以替换多个
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>