今天寫代碼的時候遇到這個錯誤
Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute application@label value=(@string/app_name) from AndroidManifest.xml:18:9-42
is also present at [org.litepal.android:core:1.6.0] AndroidManifest.xml:13:9-41 value=(@string/app_name).
Suggestion: add 'tools:replace="android:label"' to <application> element at AndroidManifest.xml:14:5-67:19 to override.
這個錯誤是因爲你導入的一些第三方的庫定義了與主項目相同的屬性。
上面的提示就是litepal
這個庫和主項目AndroidManifest
文件中的label
屬性有衝突。而且提示用也給出瞭解決的方法就是在AndroidManifest
的application
節點下加上tools:replace="android:label"
<application
android:name=".base.MyApplication"
android:allowBackup="true"
android:icon="@mipmap/logo_128"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
tools:replace="android:icon, android:label, android:theme">
...
</application>
如果加上之後,可以編譯了,但是APP的名字還是使用了第三方庫中的app_name
,我們可以這樣解決,在自己的strings.xml
中將app_name
換一下,比如換成app_name_
<string name="app_name_">移動APP</string>
然後清單文件就如下了
<application
android:name=".base.MyApplication"
android:allowBackup="true"
android:icon="@mipmap/logo_128"
android:label="@string/app_name_"
android:screenOrientation="portrait"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
tools:replace="android:icon, android:label, android:theme">
...
</application>
這樣再運行就能用回自己的命名了。