Android 开发问题:主模块和依赖模块的 Android Manifest 合并冲突
  • 在 Android 开发中,集成 mupdf-android 的示例做为模块使用,运行项目时,出现如下错误信息
> Task :view:processDebugMainManifest FAILED D:\AndroidCode\AndroidSimple\view\src\main\AndroidManifest.xml:7:9-41 Error: Attribute application@label value=(@string/app_name) from AndroidManifest.xml:7:9-41 is also present at [:mupdf] AndroidManifest.xml:21:9-44 value=(@string/mupdf_title). Suggestion: add 'tools:replace="android:label"' to <application> element at AndroidManifest.xml:4:5-30:19 to override.
问题原因
  1. 这个问题表示主模块和依赖模块的 Android Manifest 合并冲突

  2. 在主模块和依赖模块的 AndroidManifest.xml 文件中都定义了application@label,在合并时无法自动决定选用哪个

<applicationandroid:label="@string/app_name"...>
<applicationandroid:label="@string/mupdf_title"...>
处理策略
  • 按照错误提示,在主模块的 AndroidManifest.xml 文件的 application 标签中添加如下内容,样就明确告诉合并器,以本模块的application@label为准,覆盖掉依赖模块中的值
tools:replace="android:label"
  • 同时,在主模块的 AndroidManifest.xml 文件的 manifest 标签中确保已声明如下内容
xmlns:tools="http://schemas.android.com/tools"