Flutter "Gradle task assembleDebug failed" in CI
Flutter’s assembleDebug is a thin wrapper over the Android Gradle build. When it "failed with exit code 1", the real error is in the Gradle output above - a dependency, SDK, or manifest problem in the Android layer.
What this error means
A flutter build apk or flutter run ends with "Gradle task assembleDebug failed with exit code 1". The headline is generic; the actionable error (e.g. an unresolved dependency or a missing SDK) appears earlier in the Gradle log.
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
Running Gradle task 'assembleDebug'...
Gradle task assembleDebug failed with exit code 1Common causes
An underlying Android/Gradle error
The exit-code-1 line only says the Gradle build failed. The cause - a version mismatch, missing SDK, or manifest conflict - is in the Gradle output above it.
Toolchain or SDK mismatch
A wrong JDK, an Android Gradle Plugin / Gradle version mismatch, or a missing Android SDK component on the runner makes the Android build fail under Flutter.
How to fix it
Run the Android build with full stacktrace
Get the real Gradle error rather than the wrapper message.
flutter build apk --debug -v
# or run Gradle directly for the full trace
cd android && ./gradlew assembleDebug --stacktrace --infoAlign the toolchain
- Use the JDK version the Android Gradle Plugin requires (JDK 17 for AGP 8.x).
- Match the Gradle wrapper version to the AGP version.
- Install the needed Android SDK platforms/build-tools on the runner.
Clean and re-fetch when state is stale
flutter clean
flutter pub get
flutter build apk --debugHow to prevent it
- Pin Flutter, JDK, AGP, and Gradle versions together in CI.
- Read the Gradle output above the wrapper line, not just the exit code.
- Cache the Gradle and pub caches keyed on your lockfiles.