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

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

编译项目的时候,遇到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

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/722156.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-26
下一篇 2022-04-26

发表评论

登录后才能评论

评论列表(0条)

保存