快速解决Android编译报错 : Manifest merger failed with multiple errors, see logs

编译项目的时候,遇到Android Manifest合并失败的情况就挺头疼的。

Manifest merger failed with multiple errors, see logs

在这里插入图片描述

直接运行项目,看不出来问题,以前都是通过

gradlew build --debug --info --stacktrace

来排查问题,但是使用这种方式,编译就很慢,每次要等上个5、6分钟,可能还得编译几次才能解决成功,挺影响效率的。

今天发现了一个新的命令,可以专门针对Manifest来进行编译

gradlew processDebugManifest --stacktrace

这就很香了,只需要几秒钟时间,就可以排查出问题了

例如这次我编译又出现了这个报错,Manifest如下所示

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.xxxx.yyyy">
    <!--省略...-->
	<application
	        android:name=".App"
	        android:allowBackup="false"
	        android:icon="@mipmap/app_logo"
	        android:label="${APP_NAME}"
	        android:networkSecurityConfig="@xml/network_security_config"
	        android:theme="@style/AppTheme"
	        tools:replace="android:label">
	</application>
    <!--省略...-->
</manifest>

我们执行gradlew processDebugManifest --stacktrace这个命令
在这里插入图片描述
可以看到,任务花费时间3077毫秒,然后很明确地帮我们指出了出错的地方
按照这个提示,可以知道tools:replace="android:label"缺少android:allowBackup
我们给加上 tools:replace="android:label,android:allowBackup"

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.xxxx.yyyy">
    <!--省略...-->
	<application
	        android:name=".App"
	        android:allowBackup="false"
	        android:icon="@mipmap/app_logo"
	        android:label="${APP_NAME}"
	        android:networkSecurityConfig="@xml/network_security_config"
	        android:theme="@style/AppTheme"
	        tools:replace="android:label,android:allowBackup">
	</application>
    <!--省略...-->
</manifest>

再次运行,可以发现编译成功了。

PS : 需要注意的是,tools:replace里添加的属性,在app的manifest中必须要显式声明,否则就会报tools:replace specified, but no new value specified的错误了,具体可以看 https://blog.csdn.net/u010111268/article/details/102920918

猜你喜欢

转载自blog.csdn.net/EthanCo/article/details/120565856