8

i am working with react native and am trying to use expo in a bare project but whenever i try to run the app with the command npm run android, i get this error :

Execution failed for task ':expo-modules-core:compileDebugJavaWithJavac'.
> Could not resolve all files for configuration ':expo-modules-core: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: /home/dukizwe/Android/Sdk/platforms/android-31/core-for-system-modules.jar.
         > jlink executable /usr/lib/jvm/java-14-openjdk-amd64/bin/jlink does not exist.

I am using the linux OS, Android studio and JDK are correctly installed.

Inside /usr/lib/jvm/ folder, the structure look like this:

  • java-1.11.0-openjdk-amd64
  • java-1.14.0-openjdk-amd64
  • java-11-openjdk-amd64
  • java-14-openjdk-amd64
  • jdk-18

i don't know why it's looking in the java-14-openjdk-amd64 folder because in that folder there's no jlink executable.

In android studio the SDK Location si pointed to java-11-openjdk. Any help please ?

dukizwe
  • 160
  • 3
  • 9
  • If the Java 14 version is not there for you, I expect that you have installed JRE package for Java 14; e.g. `openjdk-14-jre` rather than `openjdk-14-jdk`. Use `find` to see if can find `jlink` in the `/usr/jvm` tree. – Stephen C Jul 25 '22 at 10:01
  • Looks like somewhere in the project the path of jlink has been specified to be `java-14-openjdk-amd64` folder. You should try searching for this path and correcting it. – dhakalkumar Jul 25 '22 at 10:01
  • jlink is only available in `java-11-openjdk-amd64` folder. Where exaclty can i change this path in android folder ? I searched everywhere but not find this – dukizwe Jul 25 '22 at 11:08

8 Answers8

11

You need to install the development package for Java. On debian, this is the openjdk-11-jdk package.

cdosborn
  • 3,111
  • 29
  • 30
9

I also faced same issue when I did run my React Native app on my new Ubuntu 22.x machine. I fixed it with installing JRE along with JDK.

Step 1 sudo apt install default-jre followed by java -version

should display -

Output openjdk version "11.0.14" 2022-01-18 OpenJDK Runtime Environment (build 11.0.14+9-Ubuntu-0ubuntu2) OpenJDK 64-Bit Server VM (build 11.0.14+9-Ubuntu-0ubuntu2, mixed mode, sharing)

Followed by - sudo apt install default-jdk

Check - javac -version to get output as -

Output javac 11.0.14

Hope it helps!

pjoshi
  • 249
  • 3
  • 7
3

For IntelliJ IDEA, go to: File > Project Structure and in Project tab change SDK to any SDK that uses JDK 11 or 8.

satk0
  • 170
  • 1
  • 9
2

I've just copied jlink, javac and jmod from this path:

/home/USER/android-studio/jre/bin/

to the following path:

/usr/lib/jvm/java-11-openjdk-11.0.15.0.10-1.fc36.x86_64/bin

Note: It's important to use Terminal as root

OS Used: Linux Fedora 36

Davide D'Alto
  • 7,421
  • 2
  • 16
  • 30
  • 10
    Don't copy files like this! You need to install the development package for your Java version (in my case it's Java17 on Fedora 36): sudo dnf install java-17-openjdk-devel – Tomee Aug 05 '22 at 07:08
  • thanks i instaled the devel package and it is more pratical – Victor Lukoky Sep 27 '22 at 10:04
  • Am also using Fedora. Most of my mobile projects are Cordova based and I don't have this issue on those, but hit it when I tried a new project out with Capacitor instead. The solution provided by @Tomee worked like a charm. In this instance, since I have to use Java 11 for Cordova on the same development box, Capacitor was trying to use jlink on Java 11, so I went with `sudo dnf install java-11-openjdk-devel`. After that I was able to `npx cap run android`, the point where I was previously getting the jlink does not exist error. – Neil Cresswell Sep 28 '22 at 23:01
  • Confirm this worked for me. Besides jlink I also had to copy a couple of other files. I'm limited to an older Ubuntu machine where installing the openjdk stuff properly was not an option, so this worked fine! – jeudyx Nov 21 '22 at 23:39
1

It appears that you need to set the JAVA_HOME environment variable to the parent of the jlink binary. Android Studio includes its own jlink binary. On Linux (or Mac) you can use:

export JAVA_HOME="$HOME/android-studio/jbr"

what comes after $HOME would depend on where you have Android Studio installed.

a more permanent solution is to edit your ~/.bashrc file, append the command provided above (with the path modifications if any) to the end of the said file and save changes. All done, open a new terminal and try compiling again.

On Windows you need to add the JAVA_HOME to your path

otboss
  • 621
  • 1
  • 7
  • 16
0

I had the same error, I've installed java-17-openjdk on Fedora it turns out that I also need to install java-17-openjdk-devel.

sudo dnf install java-17-openjdk java-17-openjdk-devel
jcubic
  • 61,973
  • 54
  • 229
  • 402
0

In my gradle file I had:

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    kotlin {
        jvmToolchain(8)
    }

Setting the same java version for compileOptions and kotlin closures fixed the issue:

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlin {
        jvmToolchain(8)
    }
saintmarina
  • 173
  • 2
  • 9
0

In my case, JDK was missing for Java 17. I installed it using sudo pacman -Syu jdk17-openjdk, and it worked.

You probably do not have JDK installed. You can install it from your distro's repository. For Arch Linux, check this doc.

Abdus
  • 192
  • 3
  • 10