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

相关推荐
花开月满西楼43 分钟前
保姆级【快数学会Android端“动画“】+ 实现补间动画和逐帧动画!!!
android·前端·android studio
这儿有一堆花1 小时前
打造你的 Android 图像编辑器:深入解析 PhotoEditor 开源库
android·开源
皮皮高2 小时前
itvbox绿豆影视tvbox手机版影视APP源码分享搭建教程
android·前端·后端·开源·tv
EnzoRay2 小时前
MotionEvent
android
玲小珑3 小时前
Auto.js 入门指南(七)定时任务调度
android·前端
墨狂之逸才3 小时前
adb常用命令调试
android
YoungForYou3 小时前
Android端部署NCNN
android
移动开发者1号4 小时前
Jetpack Compose瀑布流实现方案
android·kotlin
移动开发者1号4 小时前
Android LinearLayout、FrameLayout、RelativeLayout、ConstraintLayout大混战
android·kotlin
移动开发者1号4 小时前
ListView与RecyclerView区别总结
android·kotlin