AndroidStudio出現tools:replace="android:theme"問題

最近項目開發使用模塊開發,在開發過程中遇到下面問題,所以順手記錄一下。

錯誤信息

* What went wrong:
Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute application@theme value=(@style/AppTheme) from AndroidManifest.xml:35:9-40
    is also present at [TC_Hospital_Patient:zybwenzhen:unspecified] AndroidManifest.xml:17:9-47 value=(@style/AppWenzhenTheme).
    Suggestion: add 'tools:replace="android:theme"' to <application> element at AndroidManifest.xml:29:5-44:19 to override.

錯誤提示中已經給出瞭解決方案,就在最後一句話中描述了。Suggestion: add ‘tools:replace=”android:theme”’ to element at AndroidManifest.xml:29:5-44:19 to override.

錯誤描述

其實出現這個錯誤的原因是,我們的主工程中已經使用了android:theme=”@style/AppTheme”,而在module中也使用到了android:theme=”@style/AppTheme”,所以編輯器在運行程序的時候會去合併,但是合併失敗就會報此錯誤。

解決方案

解決方法就是在主工程的AndroidManifest.xml中application標籤中添加tools:replace=”android:theme”代碼,不過首先的去聲明命名空間,在manifest標籤中聲明命名空間,xmlns:tools=”http://schemas.android.com/tools”

類似問題

其中還有icon,label等都可能出現上面問題,解決類似,在Manifest.xml的application標籤下添加tools:replace=”android:icon, android:theme”(多個屬性用,隔開)


  • 其他方案

在build.gradle根標籤上加上useOldManifestMerger true 這方法有的版本不適用

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章