ERROR: JAVA_HOME is set to an invalid directory

I’m trying to build an Android Studio project with gradle, and I’m having trouble with my JAVA_HOME path. Here’s the CI error:

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

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

Here’s my .gitlab-ci.yml:

stages:

  • androidbuild

android-build:
image: alpine:latest
stage: androidbuild
before_script:
- export GRADLE_USER_HOME=‘pwd’/.GRADLE_USER_HOME
- export JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk/bin"
- chmod +x ./FrontEnd/Sally/SBdemo2/gradlew
tags:
- android_tag
script:
- cd FrontEnd/Sally/SBdemo2
- ./gradlew assemble
artifacts:
paths:
- Android_test/app/build/outputs/

Thanks!

I would set it like this:

export JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk
1 Like