| name | build-fix |
| description | Diagnose and fix Flutter build failures, including dependency conflicts, Gradle errors, compilation issues, and platform-specific build problems. Use when builds fail locally or in CI. |
Build Failure Diagnosis and Fix Skill
Expert guidance for diagnosing and fixing Flutter build failures in Android projects, including dependency conflicts, Gradle errors, and compilation issues.
When to Use This Skill
- Flutter build fails (
flutter build apk or flutter build appbundle)
- Gradle sync/build errors
- Dependency resolution failures
- Compilation errors (Dart or Kotlin/Java)
- Native build failures
- Plugin integration issues
- Version conflicts
Build Failure Diagnostic Workflow
Step 1: Identify the Build Stage
Flutter Android builds go through several stages:
- Dependency Resolution (
flutter pub get)
- Dart Compilation (
flutter build)
- Gradle Configuration (Android build system setup)
- Resource Processing (R8, ProGuard, resources)
- Native Compilation (Kotlin/Java code)
- Packaging (APK/AAB creation)
Identify which stage is failing to narrow down the issue.
Step 2: Clean Build First
Always try a clean build first:
flutter clean
cd android
./gradlew clean
cd ..
rm -rf ~/.gradle/caches
flutter pub get
flutter build apk --verbose
Step 3: Analyze Error Messages
Look for key error patterns:
- Gradle: "BUILD FAILED", "Could not resolve", "Deprecated"
- Dart: "Error:", "Warning:", "Unhandled exception"
- R8/ProGuard: "shrinking", "Missing class"
- Dependencies: "version conflict", "incompatible"
Common Build Failures and Solutions
1. Dependency Conflicts
Issue: Version Conflicts
Error: Version conflict between dependencies
Diagnosis:
cd android
./gradlew app:dependencies
Solution:
- Review
pubspec.yaml - update conflicting dependencies
- Check
android/app/build.gradle.kts for Android dependency versions
- Use version ranges carefully:
^1.0.0 vs >=1.0.0 <2.0.0
- Run
flutter pub upgrade --major-versions if needed
Issue: Missing Dependencies
Error: Could not find dependency
Solution:
- Check dependency name spelling in
pubspec.yaml
- Verify dependency exists on pub.dev
- Check internet connection
- Clear pub cache:
flutter pub cache repair
2. Gradle Build Errors
Issue: Gradle Version Incompatibility
Error: Gradle version X.X is required
Solution:
- Update Gradle wrapper:
cd android && ./gradlew wrapper --gradle-version=8.0
- Check
android/gradle/wrapper/gradle-wrapper.properties
- Ensure Java 17 is installed:
java -version
Issue: Gradle Daemon Issues
Error: Gradle daemon stopped unexpectedly
Solution:
- Stop daemon:
cd android && ./gradlew --stop
- Clear Gradle cache:
rm -rf ~/.gradle/caches
- Check memory settings in
gradle.properties
- For CI, use
android/gradle-ci.properties
Issue: Deprecated Gradle Configuration
Warning: The following Gradle features are deprecated
Solution:
- Review
android/build.gradle.kts and android/app/build.gradle.kts
- Update Gradle plugin version
- Check for deprecated DSL usage
- Run
./gradlew --warning-mode all for details
3. Java/JVM Issues
Issue: Wrong Java Version
Error: Compilation failed: java.lang.UnsupportedClassVersionError
Solution:
- This project requires Java 17
- Check:
java -version
- Set JAVA_HOME:
export JAVA_HOME=/path/to/java17
- Verify in gradle files:
JavaVersion.VERSION_17
Issue: Out of Memory
Error: GC overhead limit exceeded
Solution:
4. R8/ProGuard Issues
Issue: Class Not Found After R8 Shrinking
Error: Missing class referenced from: ...
Solution:
Issue: R8 Fails
Error: R8 task failed
Solution:
- Update Android Gradle Plugin
- Check for incompatible ProGuard rules
- Try R8 full mode:
android.enableR8.fullMode=true
- Use
--verbose flag to see details
5. Native Code Issues
Issue: Kotlin Compilation Fails
Error: Kotlin compilation failed
Solution:
- Check Kotlin version in
android/build.gradle.kts
- Review Kotlin code in
android/app/src/main/kotlin/
- Ensure Kotlin plugin version matches Gradle
- Update to latest stable Kotlin version
Issue: NDK/Native Library Issues
Error: Could not find NDK
Solution:
- Install NDK via Android Studio or SDK Manager
- Set
ANDROID_NDK_HOME environment variable
- Check if dependency actually needs NDK
- Consider excluding unwanted ABIs in
build.gradle.kts
6. Resource Issues
Issue: Duplicate Resources
Error: Duplicate resources
Solution:
- Check
android/app/src/main/res/ for duplicates
- Review resource merging in
build.gradle.kts
- Use resource prefixes to avoid conflicts
- Exclude duplicates from dependencies
Issue: Missing Resources
Error: Resource not found
Solution:
- Verify resource files exist in correct folders
- Check resource naming (lowercase, no special chars)
- Ensure resources are in appropriate density folders
- Run
flutter pub get to regenerate
7. Plugin Integration Issues
Issue: Plugin Registration Fails
Error: Unhandled Exception: MissingPluginException
Solution:
- Run
flutter clean && flutter pub get
- Check
.flutter-plugins-dependencies
- Verify plugin in
pubspec.yaml
- Rebuild native code:
flutter build apk --verbose
Issue: Plugin Version Conflict
Error: Plugin version incompatible
Solution:
- Check plugin's minimum Flutter/Android versions
- Update Flutter SDK if needed
- Update plugin to compatible version
- Review plugin's changelog for breaking changes
8. Manifest Issues
Issue: Manifest Merge Fails
Error: Manifest merger failed
Solution:
Issue: Permission Issues
Error: Permission denied
Solution:
- Add required permissions to
AndroidManifest.xml
- Check permission compatibility with minSdkVersion
- Review runtime permission handling in code
Project-Specific Build Configuration
This Template Uses
- Java 17: Required for optimal performance
- Gradle 8.0+: Modern build system
- Flutter 3.10.1+: Latest stable features
- Kotlin: For Android native code
- R8: Code shrinking enabled
- Parallel builds: Optimized for performance
- Build cache: Enabled for faster rebuilds
Key Files
- pubspec.yaml: Flutter dependencies
- android/build.gradle.kts: Root Gradle config
- android/app/build.gradle.kts: App-specific Gradle config
- android/gradle.properties: Local build settings
- android/gradle-ci.properties: CI-optimized settings
- android/app/src/main/AndroidManifest.xml: App manifest
Systematic Debug Approach
Level 1: Quick Fixes (Try First)
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/
rm -rf ~/.pub-cache/
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
flutter build apk --verbose --debug
Build Performance Optimization
If builds work but are slow:
Local Development
- Use
android/gradle.properties
- Enable parallel builds:
org.gradle.parallel=true
- Increase workers:
org.gradle.workers.max=4
- More memory:
org.gradle.jvmargs=-Xmx4g
- Enable configuration cache:
org.gradle.configuration-cache=true
CI Environment
- Use
android/gradle-ci.properties
- Fewer workers:
org.gradle.workers.max=2
- Less memory:
org.gradle.jvmargs=-Xmx3g
- Disable daemon:
org.gradle.daemon=false
- Disable configuration cache:
org.gradle.configuration-cache=false
Troubleshooting Checklist
Quick Reference Commands
flutter clean && flutter pub get && flutter build apk
flutter build apk --verbose
flutter pub outdated
cd android && ./gradlew app:dependencies
cd android && ./gradlew --version
./gradlew tasks --all
dart fix --apply
flutter analyze
flutter pub upgrade
flutter doctor -v
flutter build apk --debug
flutter build apk --profile
flutter build apk --release
When to Seek Help
If after trying all solutions the build still fails:
-
Document the issue:
- Full error message
- Build command used
- Flutter doctor output
- Java version
- Steps already tried
-
Check resources:
- Project's TROUBLESHOOTING.md
- Flutter GitHub Issues
- Stack Overflow
- Plugin's GitHub Issues
-
Create minimal reproduction:
- Start with
flutter create test_app
- Add dependencies one by one
- Identify which dependency causes issue
Additional Resources