【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 文件。

相关推荐
宝杰X714 小时前
Android Room3 多平台数据库
android·数据库
huibin14785236917 小时前
热缓解学习记录
android·学习
小田的博客19 小时前
SAP MM 供应商银行主数据更新报错!message R1228!
android·java·服务器
一笑的小酒馆21 小时前
Android智能猫砂盆视频加载慢卡顿问题分析
android
只会cv的小前端1 天前
七巧低代码服务端脚本使用方法
android·低代码·rxjava
1 天前
Android 自定义 View 实战:从零打造工业级全向摇杆控件(OmniJoystickView)
android·kotlin·自定义view·摇杆控件
雨白1 天前
深入理解 Kotlin 协程 (十一):以逸待劳,探秘 select 多路复用与并发安全策略
android·kotlin
hunterandroid1 天前
[Android 从零到一] Android 深度链接与 App Links:从 URI Scheme 到可验证的应用跳转
android
我命由我123451 天前
Jetpack Compose - Material Design 断点范围、WindowSizeClass、针对不同屏幕尺寸创建预览、四类导航栏
android·java·开发语言·java-ee·kotlin·android jetpack·android runtime
2501_915106321 天前
Python爬虫从零开始:七天掌握HTTP协议、数据解析与反爬策略
android·ios·小程序·https·uni-app·iphone·webview