1. 程式人生 > >Android studio應用的AndroidManifest.xml檔案中跟庫中出現相同的配置解決方案

Android studio應用的AndroidManifest.xml檔案中跟庫中出現相同的配置解決方案

問題描述

Error:(26, 9) Attribute application@icon value=(@drawable/logo) from AndroidManifest.xml:26:9
Error:(28, 9) Attribute application@theme value=(@style/ThemeActionBar) from AndroidManifest.xml:28:9
is also present at XXXX-trunk:XXXXLib:unspecified:15:9 value=(@style/AppTheme)
Suggestion: add ‘tools:replace=”android:theme”’ to element at AndroidManifest.xml:24:5 to override
Error:Execution failed for task ‘:XXXX:processDebugManifest’.
Manifest merger failed with multiple errors, see logs

原因

AS的Gradle外掛預設會啟用Manifest Merger Tool,若Library專案中也定義了與主專案相同的屬性(例如預設生成的Android:icon和android:theme),則此時會合並失敗,並報上面的錯誤。

解決方案

方法1:在AndroidManifest.xml的application標籤下新增tools:replace="android:icon, android:theme"(多個屬性用”,”隔開,並且記住在manifest根標籤上加入xmlns:tools="http://schemas.android.com/tools",否則會找不到namespace哦)

方法2:在build.gradle根標籤上加上useOldManifestMerger true (懶人方法)