解决 Flutter Android 编译 Manifest merger failed allowBackup 冲突修复
排查 在 Flutter 构建 Android APK 时 Gradle 抛出 Manifest merger failed: Attribute application@allowBackup value=(true) ... is also present at ... with value=(false),分析 Android 清单合并规则与 tools:replace 属性覆盖。
问题现象
Android 在将 Flutter 主模块与其依赖的众多第三方原生插件(如推送 SDK、统计 SDK、扫码库)打包成单个 APK 时,Gradle 会启动 processDebugManifest 任务执行清单文件合并(Manifest Merger)。若主 App 的 AndroidManifest.xml 中配置了 android:allowBackup="true",而某个第三方依赖声明了 android:allowBackup="false",Gradle 会因为策略冲突坚决抛出构建失败,阻断整条 CI/CD 构建流水线。
排查分析
查看 Gradle 详细报错输出日志
定位到冲突属性与涉及的两方清单文件:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
> Manifest merger failed : Attribute application@allowBackup value=(true) from AndroidManifest.xml:15:9-36
is also present at [:third_party_lib] AndroidManifest.xml:12:9-37 value=(false).
Suggestion: add 'tools:replace="android:allowBackup"' to <application> element at AndroidManifest.xml.
检查 android/app/src/main/AndroidManifest.xml 中的 <application> 标签
确认属性定义与命名空间导入情况;
检查是否有其他冲突属性(如 android:label、android:icon)
排查多重属性冲突。
触发根因
- 宿主工程与第三方库在
AndroidManifest.xml的<application>节点上对同一系统属性设置了互斥的值; - 清单合并器无法在无人为干预的情况下自行决定以哪一方的配置为准;
- 主清单文件中缺少
xmlns:tools="http://schemas.android.com/tools"命名空间声明与tools:replace覆盖指令。
解决步骤
在主 AndroidManifest.xml 中引入 tools 命名空间
在根 <manifest> 节点补充声明:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.myapp">
在 <application> 节点中添加 tools:replace 明确指定以主工程配置覆盖第三方库
配置覆盖规则:
<application
android:label="MyApp"
android:icon="@mipmap/ic_launcher"
android:allowBackup="true"
tools:replace="android:allowBackup">
<!-- 业务 activity -->
</application>
若存在多项属性冲突以逗号分隔
如 tools:replace="android:allowBackup,android:label"。
验证确认
重新运行 ./gradlew assembleDebug:
清单合并器依据覆盖策略顺利化解互斥冲突,Android 构建成功生成目标 APK。


