Skip to content

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 ​

Step-by-Step Implementation ​

  1. Install Java Development Kit (JDK) 17

    • Download from Oracle JDK 17 or use your package manager
    • macOS Homebrew users: brew install openjdk@17
  2. Configure Flutter to use JDK 17

    bash
    flutter 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
  3. Update app-level build.gradle

    gradle
    android {
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_17
            targetCompatibility JavaVersion.VERSION_17
        }
        
        // If using Kotlin
        kotlinOptions {
            jvmTarget = JavaVersion.VERSION_17.toString()
        }
    }
  4. Update Gradle wrapper (android/gradle/wrapper/gradle-wrapper.properties)

    properties
    distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip
  5. 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:

bash
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:

  1. Modify app-level build.gradle

    gradle
    android {
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_21
            targetCompatibility JavaVersion.VERSION_21
        }
    }
  2. Update Kotlin options if applicable:

    gradle
    kotlinOptions {
        jvmTarget = '21'
    }
  3. Upgrade Gradle wrapper:

    properties
    distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip

Solution 3: Handle NDK Compatibility Warnings ​

Address plugin NDK version conflicts by:

  1. Set explicit NDK version in app/build.gradle:

    gradle
    android {
        ndkVersion "27.0.12077973" // Use value from plugin warning
    }
  2. 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 ​

  1. Maintain consistent Java versions across team members
  2. Pin JDK versions in documentation or setup scripts
  3. Update Flutter plugins regularly
    bash
    flutter pub upgrade --major-versions
  4. Verify environment after Android Studio updates:
    bash
    flutter doctor -v
    java --version

Project File References ​

android/app/build.gradle:

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:

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:

bash
flutter clean

TIP

Verify successful configuration with:

bash
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.