Android tools:replace用法

楚天乐 5285 2 条

使用场景,为什么需要Android tools:replace

假设我们使用了第三方android module,这个module处于某种原因在开发的时候使用了app_name。比如下面这样

<application
        android:icon="@mipmap/ic_launcher"
        android:allowBackup="true"
        android:backupAgent="com.github.shadowsocks.ConfigBackupHelper"
        android:extractNativeLibs="true"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:networkSecurityConfig="@xml/network_security_config"
        android:banner="@mipmap/banner">

........

</application>

我们自己app也有指定android:label,那么就会产生冲突报错大致如下

Manifest merger failed : Attribute application@label value=(Nicetry) from AndroidManifest.xml:8:9-32
    is also present at [:mymodule] AndroidManifest.xml:37:9-41 value=(@string/app_name).
    Suggestion: add 'tools:replace="android:label"' to <application> element at AndroidManifest

使用方式

打开自己app的manifest.xml,加入tools:replace="android:label"

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"       <!--- 重要:用于支持tools标记---->
    package="com.shyandsy.nicetry">
    <application
        android:name=".App"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="Nicetry"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        tools:replace="android:label"                  <!--- 重要:替换android:label---->
     > 


网友最新评论( 2 )

好东西谢谢~~~~~~

August 12th, 2021
发表我的评论
昵称 (必填)
邮箱 (必填)
网址
执行时间: 51.875114440918 毫秒