javaflutterdartandroid-studio

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
}

Solution

  • 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