AndroidStudio引用lib庫時,Gradle報的“tools:replace=”錯誤
阿新 • • 發佈:2019-02-20
1、將一個工程當做lib庫
2、主工程引用此lib庫
3、當lib庫中與主專案的Manifest中定義了相同屬性時,就會報如下錯誤:
Error:Execution failed for task ':MediaTest:processDebugManifest'. (備註:MediaTest是專案名稱)
> Manifest merger failed : Attribute application@icon value=(@mipmap/ic_launcher) from AndroidManifest.xml:5:45-79
is also present at [RobotApplication:CarvpAPIs:unspecified] AndroidManifest.xml:16:9-36 value=(@mipmap/icon).
Suggestion: add 'tools:replace="android:icon"' to <application> element at AndroidManifest.xml:5:5-14:19 to override.
這是由於AndroidStudio的Gradle外掛預設會啟用Manifest Merger Tool
解決:
由上面的錯誤資訊的Suggestion可以看出,可以在Manifest.xml檔案中加入'tools:replace="android:icon"'到Application元素中(如果有別的屬性衝突,也加入別的屬性)。
請注意:要在Manifest的跟上加入xmlns:tools="http://schemas.android.com/tools",如下圖: