VS Code中Flutter运行安卓设备报错:generateDebugBuildConfig任务失败
解决Flutter任务':generateDebugBuildConfig'执行失败的问题
问题现象
运行Flutter安卓应用时触发以下错误:
任务':generateDebugBuildConfig'执行失败。
评估任务':generateDebugBuildConfig'的'namespace'属性时出错
无法计算任务':generateDebugBuildConfig'的'namespace'属性值。无法计算'namespace'属性值。
清单文件不存在:C:\Users\xxxx\ar_flutter_app\android\src\main\AndroidManifest.xml
用户提供的清单文件内容如下:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.flutter_ar" android:versionCode="1000" android:versionName="1.0.0"> <application android:label="ar_flutter_app" 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"> <!-- Specifies an Android theme to apply to this Activity as soon as the Android process has started. This theme is visible to the user while the Flutter UI initializes. After that, this theme continues to determine the Window background behind the Flutter UI. --> <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> <!-- Don't delete the meta-data below. This is used by the Flutter tool to generate GeneratedPluginRegistrant.java --> <meta-data android:name="flutterEmbedding" android:value="2" /> </application> </manifest>
解决方案
1. 确认清单文件路径
先检查你的AndroidManifest.xml是否确实位于错误提示的路径C:\Users\xxxx\ar_flutter_app\android\src\main\下:
- 如果文件不在该位置,直接将清单文件移动到这个目录。
- 如果目录不存在,手动创建
android/src/main目录结构,再放入清单文件。
2. 修复损坏的项目结构
如果安卓模块的目录结构被破坏,可通过Flutter命令重建安卓目录:
flutter create --platforms android .
执行前记得备份当前安卓目录下的自定义配置(比如现有清单内容、图标、主题文件等),重建完成后将备份内容重新添加到对应位置。
3. 对齐namespace配置
打开android/app/build.gradle文件,确保android块下的namespace与清单文件的package属性值完全一致:
android { namespace "com.example.flutter_ar" // 其他配置项... }
4. 清理缓存并重新构建
执行以下命令清除项目缓存,消除构建残留问题:
flutter clean flutter pub get cd android && gradlew clean cd .. && flutter run
内容的提问来源于stack exchange,提问作者w c
相关产品推荐
相关产品推荐

