• Building
  • ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH (Gradle)

I just finished my android game and wanted to export it using custom build. However, when I export it, there's an error

ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.


Exit Code: 1

I tried to set JAVA_HOME and PATH using export on terminal.

export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export PATH=$PATH:$JAVA_HOME/bin

But it's still the same.

Godot Engine Version 3.2 openjdk version "11.0.10" 2021-01-19 OpenJDK Runtime Environment (build 11.0.10+9-Ubuntu-0ubuntu1.20.04) OpenJDK 64-Bit Server VM (build 11.0.10+9-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)

Have you put the variables into a file like .bash_profile or your shell type equivalent?

The simple way to test if you have everything setup is to open a new shell and testing if it can find java, just

'which java'

when I do so I get

/usr/bin/java

In any case you will need to restart your editor so the new instance can see the environment variables.

Okay, so...

I reread the Godot Docs about the android export. Turns out, it asks for Java 8, not 11. So I tried to install JAVA version 8 as well as other stuff, like JAVA_HOME, PATH, and /etc/environment.


MyName@pop-os:~$ java -version
openjdk version "1.8.0_282"
OpenJDK Runtime Environment (build 1.8.0_282-8u282-b08-0ubuntu1~20.04-b08)
OpenJDK 64-Bit Server VM (build 25.282-b08, mixed mode)

sudo gedit /etc/environment

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/bin/"

source /etc/environment

MyName@pop-os:~$ echo $JAVA_HOME
/usr/lib/jvm/java-8-openjdk-amd64/bin/

MyName@pop-os:~$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

MyName@pop-os:~$ which java
/usr/bin/java

But...

ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-8-openjdk-amd64/bin/

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

Exit Code: 1

Addendum:

I'm not sure if this is related, but I'm gonna add Export Editor Settings:

Adb: /app/bin/adb Jarsigner: /app/bin/jarsigner Debug Keystore: /home/myname/.android/debug.keystore Custom Build SDK Path: /home/myname/Android/Sdk

@dotted said: For your shell you want to path to the bin directory to find java javac javah and whatever, but JAVA_HOME should be the install directory

Um... which shell again? I googled it, but POP Shell was the first one to appear. I don't think that's what you mean.

I'm still a beginner in using Linux.

Edit:

Oh, you mean the terminal? Sorry, I just get it now.

After so long, I'm finally able to export the game to android.

I'm gonna write some steps so others can do it too.

Java Installation 1. Install Java 8 2. Open /etc/environment (sudo gedit /etc/environment) 3. Add "JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"" to /etc/environment 4. Load environment (source /etc/environment)

Android Studio Installation 1. Download & Install Android Studio 2. Accept License (In my case, I download Android 9.0)

Godot Editor Settings for Android

adb: /home/yourname/Android/Sdk/platform-tools/adb jarsigner: /usr/bin/jarsigner Debug Keystore: /home/yourname/.android/debug.keystore Custom Build SDK Path: /home/yourname/Android/Sdk

Usually its whatever shell you "login" to, this is determined by your account setting and the particular shell doesn't matter too much. So if you start a terminal window, you can type "ps" like

your-prompt$ ps PID TTY TIME CMD 2516 ttys000 0:00.04 -bash 2838 ttys000 0:06.19 vi notes.txt 26248 ttys001 0:01.26 -bash 2565 ttys002 0:02.34 -bash

Here you can see that I have several 'bash' terminals open. Each Unix shell variant has slightly different '.profile' files you can use to set your env etc. I would suggest reading up on the startup scripts for your preferred/login shell. I never retain the names for .profile and .bash_profile and .bashrc (all files related to the bash shell) because there are several flavors of Unix shells and I never muddy through env variables frequently to care.