manifest.xml中label应用名报错

今天写代码的时候遇到这个错误

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属性有冲突。而且提示用也给出了解决的方法就是在AndroidManifestapplication节点下加上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>

这样再运行就能用回自己的命名了。

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