Flutter Android Build Failure After Android Studio Ladybug Update
Problem Statement
After updating Android Studio to the Ladybug version (2024.2.1), many Flutter developers encounter critical build failures when running applications on either emulators or physical devices. The error typically manifests as:
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':google_sign_in_android:compileDebugJavaWithJavac'.
Could not resolve all files for configuration ':google_sign_in_android:androidJdkImage'.
Failed to transform core-for-system-modules.jar...
The error message references a specific plugin (google_sign_in_android
in this case), but the issue affects multiple Flutter plugins. Common symptoms include:
- Failed builds regardless of specific plugins used
- "Execution failed for task" errors during compilation
- JDK image transformation failures
- Gradle task
assembleDebug
failing with exit code 1 - Persistence of the issue after removing problematic plugins
This occurs because Android Studio Ladybug bundles a Java runtime that's incompatible with Flutter's plugin ecosystem. The bundled Java version lacks backward compatibility required by Gradle for Flutter projects.
Solutions
Solution 1: Configure Java 17 (Recommended)
Step-by-Step Implementation
Install Java Development Kit (JDK) 17
- Download from Oracle JDK 17 or use your package manager
- macOS Homebrew users:
brew install openjdk@17
Configure Flutter to use JDK 17
bashflutter config --jdk-dir <path-to-java-17-home>
Example paths:
- macOS:
/opt/homebrew/opt/openjdk@17
(Homebrew) or/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
- Windows:
C:\Program Files\Java\jdk-17
- Linux:
/usr/lib/jvm/java-17-openjdk-amd64
- macOS:
Update app-level
build.gradle
gradleandroid { compileOptions { sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 } // If using Kotlin kotlinOptions { jvmTarget = JavaVersion.VERSION_17.toString() } }
Update Gradle wrapper (
android/gradle/wrapper/gradle-wrapper.properties
)propertiesdistributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip
Restart development environment
- Fully restart Android Studio and terminal sessions
- Invalidate caches: File > Invalidate Caches / Restart
Solution 1A: macOS Homebrew Path Configuration
If you installed Java via Homebrew, additional path setup is required:
sudo ln -sfn /opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk
echo 'export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"' >> ~/.zshrc # or ~/.bashrc
source ~/.zshrc # Reload shell configuration
Solution 2: Update Project to Java 21 (Advanced)
For projects ready for the latest toolchain:
Modify app-level
build.gradle
gradleandroid { compileOptions { sourceCompatibility JavaVersion.VERSION_21 targetCompatibility JavaVersion.VERSION_21 } }
Update Kotlin options if applicable:
gradlekotlinOptions { jvmTarget = '21' }
Upgrade Gradle wrapper:
propertiesdistributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
Solution 3: Handle NDK Compatibility Warnings
Address plugin NDK version conflicts by:
Set explicit NDK version in
app/build.gradle
:gradleandroid { ndkVersion "27.0.12077973" // Use value from plugin warning }
Disable NDK auto-configuration (alternative):
gradle// Comment out Flutter's automatic version // ndkVersion = flutter.ndkVersion
Explanation of Solutions
Why Java 17/21?
Android Studio Ladybug bundles JDK versions that break backward compatibility with Flutter plugins. By configuring a compatible standalone JDK:
- Ensures JDK image files transform correctly
- Maintains compatibility with Gradle's JVM requirements
- Resolves the
androidJdkImage
configuration failures - Aligns with Flutter's recommended Java versions
Why Gradle Updates?
- Gradle 8.9/8.10.2 provides better Java 17/21 support
- Fixes incompatibilities with Android Gradle Plugin 8.7.1+
- Addresses "source/target value obsolete" warnings
Why Explicit NDK Version?
- Plugins may require specific NDK versions
- Ensures native code compatibility across plugins
- Prevents unresolved symbol errors at runtime
Best Practices for Prevention
- Maintain consistent Java versions across team members
- Pin JDK versions in documentation or setup scripts
- Update Flutter plugins regularlybash
flutter pub upgrade --major-versions
- Verify environment after Android Studio updates:bash
flutter doctor -v java --version
Project File References
Recommended Configuration Files
android/app/build.gradle
:
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
// Optional: Set explicit NDK version
ndkVersion "27.0.12077973"
}
android/gradle/wrapper/gradle-wrapper.properties
:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
WARNING
After modifying any Gradle files or JDK configurations, always perform a clean build:
flutter clean
TIP
Verify successful configuration with:
flutter doctor -v
Check that "Java binary at" points to your configured JDK
Following these solutions resolves the Ladybug compatibility issue by aligning Java versions across Android Studio, Gradle, and Flutter's plugin ecosystem.