运行Flutter应用时遇Gradle构建失败:firebase_core清单解析异常
运行Flutter应用时遭遇Gradle构建失败,具体错误如下:
FAILURE: Build failed with an exception.
- What went wrong:
Execution failed for task ':firebase_core:processDebugManifest'.org.xml.sax.SAXParseException; systemId: file:/Users/user/development/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core-1.17.1/android/src/main/AndroidManifest.xml; lineNumber: 11; columnNumber: 12; Content is not allowed in trailing section.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.Get more help at https://help.gradle.org
BUILD FAILED in 23s
Exception: Gradle task assembleDebug failed with exit code 1
错误源于firebase_core-1.17.1的AndroidManifest.xml文件格式异常,根标签</manifest>尾部存在多余内容。以下是解决步骤:
修复AndroidManifest.xml文件
找到路径/Users/user/development/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core-1.17.1/android/src/main/AndroidManifest.xml,打开后检查第11行附近,删除</manifest>标签之后的所有多余字符、空格或代码,确保文件以该标签结尾且无后续内容。清理缓存并重新获取依赖
执行命令:flutter clean flutter pub get升级firebase_core版本
在项目的pubspec.yaml中,将firebase_core的版本替换为最新稳定版(例如firebase_core: ^2.15.0),然后执行flutter pub get拉取新依赖。重新构建项目
执行flutter run重新运行应用,验证问题是否解决。
内容的提问来源于stack exchange,提问作者Lets Done This

