Kotlin could not find the required JDK tools in the Java installation '/usr/lib/jvm/java-8-openjdk-amd64/jre' used by Gradle. Make sure Gradle is running on a JDK, not JRE

Gradle finds wrong JAVA_HOME even though it’s correctly set!

Kotlin could not find the required JDK tools in the Java installation ‘/usr/lib/jvm/java-8-openjdk-
amd64/jre’ used by Gradle. Make sure Gradle is running on a JDK, not JRE.

System: Linux Mint 19.1 64-bit

So i just downloaded flutter and trying to run the helloworld app, I get this error.
I’m not sure why i get this error, my default java points to the JDK version.

When I run the following code snippet from the gradlew file from the flutter project,

    if [ -n "$JAVA_HOME" ] ; then
         if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
             # IBM's JDK on AIX uses strange locations for the executables
             JAVACMD="$JAVA_HOME/jre/sh/java"
         else
             JAVACMD="$JAVA_HOME/bin/java"
             echo $JAVACMD
         fi
     fi

Output: /usr/lib/jvm/java-8-openjdk-amd64/bin/java

I ran update-alternatives and configured it as following,

sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      auto mode
* 1            /usr/lib/jvm/java-8-openjdk-amd64/bin/java       1         manual mode
  2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode
  3            /usr/lib/jvm/java-ibm-x86_64-80/jre/bin/java     80        manual mode

Contents of /usr/lib/jvm/ directory

ls -l /usr/lib/jvm/
total 8
lrwxrwxrwx  default-java -> /usr/lib/jvm/java-8-openjdk-amd64/
lrwxrwxrwx  ibm-java80-jre-x86_64 -> java-ibm-x86_64-80
lrwxrwxrwx  java-1.8.0-openjdk-amd64 -> java-8-openjdk-amd64
drwxr-xr-x  java-8-openjdk-amd64
drwxr-xr-x  java-ibm-x86_64-80

Few other things I’ve tried,

  1. Reinstall flutter and SDK Manager
  2. Create default-java folder with symlink in the /usr/lib/jvm directory
  3. Declared JAVA_HOME in the gradlew file itself
    None of them helped.

How do I make gradle use the JDK version?

P.S. - followed this to setup flutter: https://levelup.gitconnected.com/how-to-install-flutter-without-android-studio-on-ubuntu-6d8b55741afa

3 Likes