Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter 3.24.3 problem with Android Studio Ladybug | 2024.2.1

When I update Android studio to last version "Ladybug 2024.2.1" an error occur whenever I run application in android emulator or physical phone, this problem shows an error with a specific library but in fact it occur with all libraries, I know that because every library tell me there is an error with, I just try to remove it then try running the code again.

This is the error:

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 to match attributes {artifactType=_internal_android_jdk_image, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}. Execution failed for JdkImageTransform: /Users/zaydahmad/Library/Android/sdk/platforms/android-34/core-for-system-modules.jar. Error while executing process /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/jlink with arguments {--module-path /Users/zaydahmad/.gradle/caches/transforms-3/fd4e2b69c2691a24d99d2b3c10c60f94/transformed/output/temp/jmod --add-modules java.base --output /Users/zaydahmad/.gradle/caches/transforms-3/fd4e2b69c2691a24d99d2b3c10c60f94/transformed/output/jdkImage --disable-plugin system-modules}

Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. Get more help at https://help.gradle.org.

BUILD FAILED in 9s Error: Gradle task assembleDebug failed with exit code 1

I have update all the libraries to the last version. I have remove every library appear with that error, it doesn't work.

maybe these files help you solve the problem:

android/app/build.gradle

android {
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
}

android/gradle/wrapper/gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip

android/build.gradle

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = "../build"
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(":app")
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}
like image 771
Harith Bashar Avatar asked Nov 18 '25 22:11

Harith Bashar


2 Answers

The issue comes from Android Studio Ladybug having bundled a version of Java that isn't fully backward compatible with Flutter's plugin ecosystem. The solution is to separately install a version of Java (such as Java 17) and configure your project to use it.

  1. Install Java SDK 17 using your method of choice* (either manually or using a runtime manager such as asdf).

  2. Run this command pointing at the location where you installed Java SDK 17:

    flutter config --jdk-dir <path-to-java-sdk-17-home-directory>
    
  3. (Optional, but some plugins may require it) Open android/app/build.gradle and update your Java compatibility options:

    android {
        compileOptions {
          sourceCompatibility JavaVersion.VERSION_17
          targetCompatibility JavaVersion.VERSION_17
        }
    
        // If using Kotlin
        kotlinOptions {
            jvmTarget = JavaVersion.VERSION_17
        }
    }
    

Further reading:

  • How to fix Android Compilation issues in Android Studio Ladybug.
  • Android build warnings about Java with latest Gradle: source value 8 is obsolete/target value 8 is obsolete
  • Flutter Android Gradle Migration Guide
  • Gradle-Toolchain-Java Compatibility Matrix

*: If you install the JDK via Homebrew, you may need to update your PATH and/or JAVA_HOME as laid out in @prensj's answer.

like image 103
Abion47 Avatar answered Nov 20 '25 13:11

Abion47


Thanks to Sergio's comment above:

if you use brew install openjdk@17 to install jdk, you need to set java_home with this commands: 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 and after: flutter config --jdk-dir /opt/homebrew/opt/openjdk@17

I personally had this issue arise when I upgraded from Android Studio Jellyfish to LadyBug.

I believe the issue stems from the Android Studio default JAVA runtime not being backwards compatible with some flutter plugins / gradio.

My solution was to change the Java runtime to 17, as it is compatible with the version of gradio I am using.

The problem I then faced was trying to set JAVA_HOME.

I had installed Java 17 with brew and Android Studio did not like the PATH.

The Solution:

Install Java 17 via brew

  1. brew install openjdk@17

Create a symbolic link for the Java 17

  1. sudo ln -sfn /opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk

Add path to the symbolic link (I am using zsh, change to ~/.bashrc if you use bash)

  1. echo 'export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"' >> ~/.zshrc

Configure Flutter to use the install Java 17

  1. flutter config --jdk-dir /opt/homebrew/opt/openjdk@17

  2. Restart Terminal and Android Studio

  3. Run you AVD

  4. flutter run

like image 44
prensj Avatar answered Nov 20 '25 11:11

prensj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!