Issue
I am currently trying to create a .gitlab-ci.yml file in which an Android Studio project is automatically build. The file structure in my GIT repo looks like this:
the_app
.gitlab-ci.yml
README.md
My .gitlab-ci.yml looks like this:
image: jangrewe/gitlab-ci-android
variables:
ANDROID_COMPILE_SDK: "30"
before_script:
- export GRADLE_USER_HOME=$(pwd)/.gradle
- apt-get update -y && apt-get install wget -y
build:
script:
- cd ./ISSD_application
- chmod +x ./gradlew
- ./gradlew assembleDebug
artifacts:
paths:
- app/build/outputs/
But now I get the error that says:
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.
The Java installation that is used for the Android project is on my computer and not in the GIT-repo. How can I set the JAVA_HOME variable correctly so the project can build?
Solution
Indeed JAVA_HOME
is not set in the image but java binary is located under /usr/bin/java
.
You can set JAVA_HOME
in the same way you set GRADLE_USER_HOME
, in before_script
section :
before_script:
- export GRADLE_USER_HOME=$(pwd)/.gradle
- export JAVA_HOME="/usr/bin/java"
- apt-get update -y && apt-get install wget -y
Answered By - Nicolas Pepinster
Answer Checked By - Marilyn (JavaFixing Volunteer)