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

I am also getting the same error this is my .gitlab-ci.yml file:
stages:

  • deploy
    deploy_to_google_play:
    stage: deploy
    script:
    • export JAVA_HOME=“/Users/apple/Library/Java/JavaVirtualMachines/corretto-17.0.9/Contents/Home”
    • npx jetify
    • cd android/
    • bundle exec fastlane buildReleaseAPK
      only:
    • production

Can any one help please.
Thanks!