"ERROR: JAVA_HOME is set to an invalid directory" for android build

(cli) openfl build android
(long logs)

ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm

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

I have already tried setting $JAVA_HOME to “/usr/lib/jvm/default-java” and “/usr/lib/jvm/java-17-openjdk-amd64/bin/java”.

But interestingly. The program still keeps insisting my “JAVA_HOME” env variable is set to “/usr/lib/jvm” even thought it’s not.

I have already closed and re-opened my terminal.

I have already tried “source ~/.bashrc” with JAVA_HOME being set to several different paths, and still nothing.

I have tried to “force it” like: “JAVA_HOME=(path…); openfl build android” but it seems it’s “getting” the env variables from somewhere else.

The “.env” file in the current directly does not exist so it can’t be it.

Here are some program output to help:

Vik@Vik: pts/0: 7 files 36Kb ❯ java --version
openjdk 17.0.1 2021-10-19
OpenJDK Runtime Environment (build 17.0.1+12-Ubuntu-121.04)
OpenJDK 64-Bit Server VM (build 17.0.1+12-Ubuntu-121.04, mixed mode, sharing)

Vik@Vik: pts/0: 7 files 36Kb ❯ cat Build.xml
<xml> <set name="HXCPP_ARM64" value="1" if="android" /> <files id="hello"> <file name="Hello.cpp" /> </files> <target id="default" output="hello" tool="linker" toolid="${STD_MODULE_LINK}"> <outdir name="bin" /> <ext value="" /> <files id="hello" /> </target> </xml>

Vik@Vik: pts/0: 7 files 36Kb ❯ cat project.xml
<?xml version="1.0" encoding="utf-8"?> <project> <meta title="HelloWorldProject" package="com.sample.helloworldproject" version="1.0.0" company="Company Name" /> <app main="Main" path="Export" file="HelloWorldProject" /> <source path="Source" /> <haxelib name="openfl" /> <config:android build-tools-version="1" /> <assets path="Assets" rename="assets" /> </project>

Vik@Vik: pts/0: 7 files 36Kb ❯ haxe --version
4.1.5

Vik@Vik: pts/0: 7 files 36Kb ❯ echo $JAVA_HOME
/usr/lib/jvm/java-17-openjdk-amd64/bin/java

Thanks.

“lime setup android” stores settings here ~/.lime/config.xml
check the file

Thanks it worked.

But now I get the error:

“Failed to find target with hash string ‘android-30’ in: /opt/android-sdk”

Not sure what todo.

I’m very close I can feel it.

The answers on this Stack Overflow question about that error message seem to indicate that you need to open Android Studio’s SDK manager and download the Android SDK platform for API level 30.