【Android】application@label 属性属性冲突报错

错误记录
java 复制代码
 What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
> Manifest merger failed : Attribute application@label value=(@string/app_name) from AndroidManifest.xml:8:9-41
  	is also present at [:abslibrary] AndroidManifest.xml:25:9-47 value=(@string/app_name_next).
  	Suggestion: add 'tools:replace="android:label"' to <application> element at AndroidManifest.xml:5:5-21:19 to override.
原因

这个错误是因为在主项目的 AndroidManifest.xml 文件和 abslibrary模块的 AndroidManifest.xml 文件中都定义了 application@label 属性,且它们的值不一致。Gradle 在合并这些清单文件时遇到冲突,导致构建失败。

具体来说:

主项目的 AndroidManifest.xml 中定义了 application@label 为 @string/app_name,而abslibrary模块的 AndroidManifest.xml 中定义了 application@label 为 @string/app_name_next。

这两个 application@label 属性的值不同,导致在合并清单文件时发生冲突。

解决方案

有两种常见的解决方法来解决这个问题:

  1. 使用 tools:replace 来强制覆盖

你可以在主项目的 AndroidManifest.xml 文件中的 标签上添加 tools:replace="android:label",这样 Gradle 会在合并清单文件时使用主项目中的 application@label 属性值,而忽略 abslibrary中的值。

具体操作步骤:

打开主项目的 AndroidManifest.xml 文件。

在 标签中添加 tools:replace="android:label" 属性,如下所示:

java 复制代码
<application
   android:label="@string/app_name"
   android:icon="@mipmap/ic_launcher"
   tools:replace="android:label">
   <!-- 其他配置 -->
</application>

这样,tools:replace 会强制覆盖 application@label 属性,避免合并冲突。

注意:使用 tools:replace 需要在 AndroidManifest.xml 文件的顶部添加 xmlns:tools="http://schemas.android.com/tools" 声明:

java 复制代码
 <manifest xmlns:tools="http://schemas.android.com/tools" ... >
  1. 修改 abslibrary 模块中的 AndroidManifest.xml 文件

如果你希望 abslibrary 中的 application@label 属性生效,你可以修改 abslibrary 模块中的 AndroidManifest.xml 文件,删除或更改其中的 android:label 属性。

例如,在 abslibrary 模块的 AndroidManifest.xml 中,将:

java 复制代码
<application
    android:label="@string/app_name_south"
    ... >
</application>

改成不设置 android:label,或者将其值更改为和主项目一致的值,或者删除这一行配置。这样,abslibrary 模块就不会再引发冲突。

推荐的做法

一般来说,推荐使用第一个方法(即使用 tools:replace="android:label"),因为这样可以确保主项目的 application@label 属性值优先级更高,且不需要修改第三方库(如 abslibrary )的 AndroidManifest.xml 文件。

相关推荐
liang_jy9 小时前
Android 窗口容器树(一)—— 窗口和窗口容器树
android·源码
HUGu RGIN10 小时前
MySQL--》如何在MySQL中打造高效优化索引
android·mysql·adb
Joseph Cooper12 小时前
Linux/Android 跟踪技术:ftrace、TRACE_EVENT、atrace、systrace 与 perfetto 入门
android·linux·运维
空中海13 小时前
安卓逆向03. 动态调试、抓包分析与 Frida Hook
android
一起搞IT吧14 小时前
相机Camera日志实例分析之二十:相机Camx【照片后置4800/5000/6400万拍照】单帧流程日志详解
android·嵌入式硬件·数码相机·智能手机
jinanwuhuaguo15 小时前
(第三十三篇)五月的文明奠基:OpenClaw 2026.5.2版本的文明级解读
android·java·开发语言·人工智能·github·拓扑学·openclaw
千码君201616 小时前
Trae:一些关于flutter和 go前后端开发构建的分享
android·flutter·gradle·android-studio·trae·vibe code
重生之我是Java开发战士20 小时前
【MySQL】事务 & 用户与权限管理
android·数据库·mysql
怣疯knight1 天前
Windows不安装 Android Studio如何打包安卓软件
android·windows·android studio
ke_csdn1 天前
从Java演变到Kotlin下的jet pack
android