Flutter集成自定义求和AAR遇Manifest合并及解析错误求助
Flutter集成自定义求和AAR的Manifest合并错误解决指南
问题场景
开发了一个接收参数a、b并返回求和结果的AAR文件,将其集成到Flutter项目时,遇到两次Manifest相关构建错误:
首次报错
FAILURE: Build failed with an exception.
- What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
Manifest合并失败:来自未知来源的application@label值=(aar_methods),与[:com.example.addaar-addition-1.0.0:] AndroidManifest.xml:15:9-41中的值=(@string/app_name)重复。
建议:在AndroidManifest.xml:4:5-35:19的元素中添加'tools:replace="android:label"'以覆盖。
修改后新报错
FAILURE: Build failed with an exception.
- What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
com.android.manifmerger.ManifestMerger2$MergeFailureException: 解析/home/santosh/VsCode/sample/aar_methods/android/app/src/main/AndroidManifest.xml内容时出错
解决步骤
1. 正确配置tools命名空间与label覆盖
直接修改Flutter项目的android/app/src/main/AndroidManifest.xml,先在根manifest标签中添加tools命名空间,再在application标签中添加覆盖指令:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.example.your_flutter_app"> <application android:label="你的Flutter应用名称" tools:replace="android:label" android:icon="@mipmap/ic_launcher"> <!-- 原有配置内容保留 --> </application> </manifest>
注意:必须先声明tools命名空间,否则tools:replace会被视为无效属性,引发解析错误。
2. 修复Manifest文件语法问题
第二次报错是XML解析失败,检查以下几点:
- 所有XML标签是否完整闭合(比如
<activity>必须对应</activity>,无遗漏) - 属性值是否全部用双引号包裹(例如
android:label="xxx",不能用单引号或无引号) - 文件中是否存在乱码、特殊字符或格式错误的标签
3. 优化AAR的Manifest配置(可选)
如果上述步骤仍未解决,检查自定义AAR的AndroidManifest.xml:
- 尽量不要在AAR的Manifest中设置
android:label,交给Flutter项目统一管理 - 若AAR必须保留该属性,确保其引用的字符串资源在Flutter项目的
res/values/strings.xml中存在,或者通过tools:replace完全覆盖
内容的提问来源于stack exchange,提问作者Santosh Korada
相关产品推荐
相关产品推荐

