| name | build-fix |
| description | Diagnose and fix Flutter build failures including dependency conflicts, Gradle errors, compilation issues, and platform-specific build problems |
Build Failure Diagnosis and Fix
Expert guidance for diagnosing and fixing Flutter build failures in Android projects.
When to Use
flutter build apk or flutter build appbundle fails
- Gradle sync/build errors
- Dependency resolution failures
- Dart or Kotlin/Java compilation errors
- Plugin integration issues
- Version conflicts
Build Stages
Flutter Android builds go through these stages:
- Dependency Resolution (
flutter pub get)
- Dart Compilation (
flutter build)
- Gradle Configuration (Android build system)
- Resource Processing (R8, ProGuard)
- Native Compilation (Kotlin/Java)
- Packaging (APK/AAB creation)
Identify which stage is failing first.
Systematic Debug Approach
Level 1: Quick Fix
flutter clean
flutter pub get
flutter build apk --verbose
Level 2: Gradle Reset
cd android && ./gradlew clean && ./gradlew --stop && cd ..
flutter clean && flutter pub get
flutter build apk --verbose
Level 3: Cache Clear
flutter clean
rm -rf ~/.gradle/caches/
flutter pub cache repair
flutter pub get
flutter build apk --verbose
Level 4: Deep Dive
flutter doctor -v
java -version
cd android && ./gradlew app:dependencies
./gradlew assembleRelease --stacktrace --info
Common Failures
Dependency Conflicts
- Check
pubspec.yaml version constraints
- Run
flutter pub outdated and flutter pub upgrade
- Check
android/app/build.gradle.kts for Android dependency versions
Gradle Issues
- Verify Java 17:
java -version
- Update wrapper:
cd android && ./gradlew wrapper --gradle-version=8.0
- Check memory in
android/gradle.properties (4GB local, 3GB CI)
- For CI, use
android/gradle-ci.properties
R8/ProGuard Issues
- Add keep rules in
android/app/proguard-rules.pro
- Temporarily disable shrinking to test:
shrinkResources false
Manifest Merge Failures
- Check
android/app/src/main/AndroidManifest.xml
- Use
tools:replace or tools:merge attributes for conflicts
Key Project Files
pubspec.yaml - Flutter dependencies
android/build.gradle.kts - Root Gradle config
android/app/build.gradle.kts - App Gradle config (Java 17, R8 enabled)
android/gradle.properties - Local build settings (4GB heap, 4 workers)
android/gradle-ci.properties - CI settings (3GB heap, 2 workers)
Quick Reference
flutter clean && flutter pub get && flutter build apk
flutter build apk --verbose
flutter pub outdated
dart fix --apply && flutter analyze
flutter doctor -v