You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter Debug构建失败求助:Gradle任务assembleDebug执行异常

Fixing Flutter Gradle Build Failure (Exit Code 1)

Hey there, let's work through this build issue step by step. First, here's the error context you shared:

FAILURE: 构建失败,出现异常。
位置: 脚本 'C:\src\flutter\flutter\packages\flutter_tools\gradle\flutter.gradle' 第1035行
错误原因: 任务 ':app:compileFlutterBuildDebug' 执行失败。
进程 'command 'C:\src\flutter\flutter\bin\flutter.bat'' 以非零退出值1结束
尝试解决方法:
使用 --stacktrace 参数获取堆栈跟踪信息。
使用 --info 或 --debug 参数获取更多日志输出。
使用 --scan 参数获取完整分析信息。
构建耗时11秒后失败
异常: Gradle任务assembleDebug执行失败,退出码为1

This generic exit code 1 error usually hides a more specific issue—let's dig into fixes that commonly resolve this:

Step 1: Get Detailed Error Logs

The first thing you need is actual context about what's breaking. Run either of these commands to reveal the root cause:

  • flutter run --debug --stacktrace
  • flutter build debug --verbose

These will show you specifics like dependency conflicts, invalid assets, syntax errors, or missing SDK components that the generic message skips.

Step 2: Clear Corrupted Caches

Caches go bad all the time—let's wipe and refresh them:

  • Run flutter clean to delete Flutter's build artifacts
  • Delete the .gradle folders in both your project root and the android subdirectory
  • Run flutter pub get to re-fetch all dependencies
  • Try building again with flutter run

Step 3: Validate Your Flutter Environment

Run flutter doctor and fix every issue it flags. Common fixes here include:

  • Installing missing Android SDK components
  • Accepting Android licenses (run flutter doctor --android-licenses to do this quickly)
  • Upgrading Flutter/Dart to the latest stable version with flutter upgrade

Step 4: Sync Gradle Versions

Mismatched Gradle and Android Gradle Plugin versions are a frequent culprit:

  1. Open android/build.gradle and update the com.android.tools.build:gradle version to one compatible with your Flutter release
  2. Open android/gradle/wrapper/gradle-wrapper.properties and update the distributionUrl to match the Gradle version you're using (e.g., https\://services.gradle.org/distributions/gradle-7.5-all.zip)

Step 5: Check for Project-Specific Errors

  • Run flutter analyze to catch syntax mistakes, unused code, or misconfigured assets
  • Double-check that all assets (like images) are correctly listed in pubspec.yaml and don't have special characters in their filenames
  • Use flutter pub outdated to spot outdated packages that might be causing conflicts

If none of these steps fix the problem, share the detailed logs from Step 1, and we can narrow it down further!

内容的提问来源于stack exchange,提问作者Odai Shaglouf

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 21:12:34