Flutter构建报错:generateDebugBuildConfig任务执行失败求助
Flutter构建失败:AndroidManifest.xml不存在的解决办法
报错信息
FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':generateDebugBuildConfig'. > Error while evaluating property 'namespace' of task ':generateDebugBuildConfig' > Failed to calculate the value of task ':generateDebugBuildConfig' property 'namespace'. > Failed to calculate the value of property 'namespace'. > Manifest file does not exist: E:\My Projects\MobileApp\herb_identifier\android\src\main\AndroidManifest.xml * 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 4s Exception: Gradle task assembleDebug failed with exit code 1
解决步骤
验证文件路径与存在性
直接前往报错路径E:\My Projects\MobileApp\herb_identifier\android\src\main\确认AndroidManifest.xml是否存在。可能的问题包括:文件被误删除、项目目录被移动/重命名、路径包含空格/特殊字符导致识别异常。如果是路径问题,建议将项目迁移到无空格的目录下,比如E:\Projects\MobileApp\herb_identifier。重建缺失的Manifest文件
如果文件确实丢失,可通过两种方式恢复:- 创建一个新的Flutter测试项目,将新项目中
android\src\main\AndroidManifest.xml复制到当前项目对应路径; - 手动创建该文件,使用标准Flutter Manifest模板(记得替换包名和应用名称):
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.yourpackage.herb_identifier"> <application android:label="herb_identifier" android:name="${applicationName}" android:icon="@mipmap/ic_launcher"> <activity android:name=".MainActivity" android:exported="true" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize"> <meta-data android:name="io.flutter.embedding.android.NormalTheme" android:resource="@style/NormalTheme" /> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> <meta-data android:name="flutterEmbedding" android:value="2" /> </application> </manifest>- 创建一个新的Flutter测试项目,将新项目中
重置项目配置与依赖
执行以下命令清理并重建项目配置:flutter clean flutter pub get cd android gradlew clean cd .. flutter run也可以尝试用Android Studio打开项目的
android模块,让IDE自动修复项目结构和Gradle依赖问题。检查版本兼容性
运行flutter doctor检查Flutter环境,确认Flutter版本与项目中Gradle、Android SDK版本兼容,根据提示进行版本更新或配置调整。
内容的提问来源于stack exchange,提问作者Richard Vidzrakou
相关产品推荐
相关产品推荐

