57

I am trying to build flutter apk on debug mode from android studio.

Flutter run I get this error:

Launching lib/main.dart on sdk gphone x86 arm in debug mode... Running Gradle task 'assembleDebug'...

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:compileDebugJavaWithJavac'.

Could not resolve all files for configuration ':app: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/mac/Library/Android/sdk/platforms/android-30/core-for-system-modules.jar. > jlink executable /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/jlink does not exist.

  • 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 20s Exception: Gradle task assembleDebug failed with exit code 1

2
  • 1
    Any solution? Same problem here Commented Dec 6, 2021 at 17:24
  • I have solved it here. Check and report if it helped you. stackoverflow.com/a/70359396/15905119 @EnzoLizama Commented Dec 15, 2021 at 8:04

20 Answers 20

112

In my flutter project, I encountered this issue after I updated my android studio to Android Studio Ladybug | 2024.2.1 here is how I solved this: Modify settings.gradle File:

Under the plugins section in your settings.gradle file, update the line having "com.android.application" with the following line:

id "com.android.application" version "8.3.2" apply false

update your gradle-wrapper.properties file with the following:

distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
Sign up to request clarification or add additional context in comments.

10 Comments

Thank you! I also got another error so I had to update the Kotlin plugin in the same section of settings.gradle.
I had a same problem after that Android Studio version update too. And your solution resloved it. thank you.
Thank you! I also got the same error and this solution worked for me...
Where would we be without Stack Overflow? Thanks for the fix.
Just a heads up that some packages can't handle the upgrade to this. So proceed with a touch of caution if you've got a lot of dependencies. (I've been yak-shaving for a week on this now!)
|
37

For me the problem reason was in incompatibility the default Java (which used by Android toolchain) and Flutter version, so I managed to get this fixed by setting the path to Java for Flutter

flutter config --jdk-dir "/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home"

Also the same solution helped for the build error

Execution failed for task ':app:compileDevDebugJavaWithJavac'. > error: invalid source release: 21

4 Comments

This solved the issue for me, and I have used JAVA version 17
This what finally worked for me! Simple and straightforward solution to this unsavoury problem.
Thank you so much, the only solution for me after 3h+
The only solution that actually helped me. Thank you!
17

I solved the same problem downgrading to jdk17 (from jdk21)

  • install openjdk17 (https://reactnative.dev/docs/environment-setup?guide=native&platform=android says You may encounter problems using higher JDK versions. Jan 2024)
  • change your JAVA_HOME to this version (on your .zshrc): export JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk-17.jdk/Contents/Home
  • remove gradle cache sudo rm -rf $HOME/.gradle
  • perform a gradle clean to rebuild the cache (cd android && ./gradlew clean && cd ..)
  • build your android project yarn react-native run-android (or npx react-native start, then "a")

stuck 3 days with this problem 🤦 hope it helps someone :)

Comments

10

I solved this issue by downloading the required NDK side by side package as shown in this screenshot for the required SDK platform.

If you keep getting errors after doing this, please share error logs or screenshots. Thanks.

Android Studio screenshot

2 Comments

Thanks. That worked for me (After updating the Android Studio I got this issue) but it was solved after upgrading the NDK as you mentioned.
Execution failed for task ':flutter_plugin_android_lifecycle:compileDebugJavaWithJavac'. >':flutter_plugin_android_lifecycle: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: ...\Android\sdk\platforms\android-34\core-for-system-modules.jar.
5

enter image description hereenter image description here

Change the Settings Gradle com.android.application to 8.3.2 Change the grdle wrapper properties version to 8.4 for Zip File gradle

Comments

3

I got the same error and checked the folder where the jdk is installed, for me this was usr/lib/jvm/... and the file jlink mentioned in the error message was missing. So i uninstalled the jdk with

sudo apt-get remove openjdk*
sudo apt-get clean

and reinstalled it with

sudo apt-get install openjdk-8-jdk

Afterwards I checked the folder again and the jlink-file was there and it worked afterwards.

I have to mention that I do not have a flutter but a react-native project, but I think the solution could be quite the same.

Comments

3

If you want to use the new JDK which is JDK 21 which is used by newer version of Android Studio then you have to update the versions in some files:

// In settings.gradle

id "com.android.application" version "8.3.2" apply false

// In gradle-wrapper replace to this:

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

Or you can set the flutter config to use the older JDK you can set that using:

flutter config --jdk-dir "C:\Users\user\.jdks\corretto-17.0.13"

Comments

2

For MacOS

run brew install openjdk@17

jre is not needed

Also, remember to set JAVA_HOME to the right folder. If you're using Intel, then it's: /usr/local/Cellar/openjdk@17/17.0.11

Comments

2

Open the project in Android Studio.
click on AGP Upgrade Assistant.
Once complete, the issue will be resolved.

Comments

1

I was having the same issue while running in WSL2, and was finally able to fix it by installing a different version of Java 17 (sudo apt install openjdk-17-jdk openjdk-17-jre instead of openjdk-17-jre-headless which I had before) and correspondingly updating the path to $JAVA_HOME (for me in .bashrc file in /home/{username}).

Comments

1

It is because jlink file is missing.

I had a similar problem on Ubuntu and solved it by running these commands: sudo apt purge openjdk-17-jre-headless, sudo apt install default-jre & sudo apt install default-jdk

Comments

1

The answers helped me figuring what went wrong, especially @ztefanie's answer. Indeed, not only the jlink file was missing, the entire path to the JDK was missing. It used to be the Android Studio embedded JDK.

For me that happened after upgrading Android Studio to the Ladybug version, for a standard Android project on macOS.

I downloaded another version of the JDK (version 21 wouldn't solve the issue so I downloaded version 17), directly from the Android Studio settings (Build, Execution, Deployment => Build => Gradle, then pick the Gradle JDK in the bottom half, then there is an option to Download a JDK)

And it could build properly, eventually.

Comments

1

Same here, I tried to launch the project in Android Studio directly and I followed the Gradle upgrade steps advised by Android Studio.

I also changed the Gradle JDK used by Android Studio because I have JDK 17 on my project but Android Sudio used JDK 21

File -> settings -> Build Executio Deployment -> Build tools -> Gradle : select YOUR_GRADLE_JDK_VERSION

See : https://docs.flutter.dev/release/breaking-changes/android-java-gradle-migration-guide

Comments

1

I got this issue because I updated my Android Studio to:

Android Studio Ladybug Feature Drop | 2024.2.2

and my $JAVA_HOME is pointing to /Applications/Android Studio.app/Contents/jbr/Contents/Home

  1. I downloaded Java 17 manually: brew install openjdk@17
  2. Changing $JAVA_HOME to /opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk/Contents/Home will NOT work
  3. I reverted to /Applications/Android Studio.app/Contents/jbr/Contents/Home
  4. Ran this instead: flutter config --jdk-dir "/opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk/Contents/Home"

Comments

0

In my case, I only need update Android Studio to newer version and it's working normally again.

Comments

0

Probably you need to downgrade java version. You can use jenv for managing java versions. Everything should be really easy, you can seehere

Comments

0

I was having this exact problem while using Ionic with Capacitor to run the livereload version of the app (debug). The issue arose when I upgraded Android Studio from Giraffe to Ladybug.

I tried most of the things in the other answers but couldn't make it work.

Then I just compiled the app for a standard build (apk) instead of the livereload project and that way actually worked.

Comments

0

it's happened with me in Android kotlin.

Then I changed these below: in project level:

 id("com.android.application") version "8.3.2" apply false
 id("org.jetbrains.kotlin.android") version "2.0.20" apply false

in build.gradle.kts ( app) I changed to this:

    compileOptions {
    sourceCompatibility = JavaVersion.VERSION_17
    targetCompatibility = JavaVersion.VERSION_17
}

kotlinOptions {
    jvmTarget = "17"
}

After this changes, it worked

Comments

0

It was resolved for me by following the steps.

OS: Ubuntu

Project: Flutter

Platform: Android

Steps 1: Updated the Java to OpenJDK-17

Step 2:gradle-wrapper.properties 
   /gradle-8.3-all.zip to /gradle-8.4-all.zip  --Updated

Step 3: settings.gradle
    plugins: id "com.android.application" 
    version "8.1.0" to version "8.3.2"   --Updated

Resolved!

I hope it will help you.

Thanks!

Comments

0

You can add this in your app-level build.gradle

android {
    namespace = "com.ronik.pass"
    compileSdk = flutter.compileSdkVersion
    ndkVersion = "25.1.8937393"

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

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8
    }

Add this in your settings.gradle

plugins {
    id "com.android.application" version "8.3.2" apply false
    id "org.jetbrains.kotlin.android" version "2.0.21" apply false
}

Change your gradle distributions version in your gradle-wrapper.properties

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.