未设置Android项目Gitlab-ci.yml JAVA_HOME



我目前正在尝试创建一个.gitlab-ci.yml文件,在该文件中自动构建Android Studio项目。我的GIT回购中的文件结构如下:

the_app
.gitlab-ci.yml
README.md

我的.gitlab-ci.yml看起来是这样的:

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/

但现在我得到的错误是:

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.

用于Android项目的Java安装在我的计算机上,而不是在GIT repo中。如何正确设置JAVA_HOME变量以便构建项目?

实际上,图像中没有设置JAVA_HOME,但java二进制文件位于/usr/bin/java下。

您可以按照设置GRADLE_USER_HOME的方式设置JAVA_HOME,在before_script部分:

before_script:
- export GRADLE_USER_HOME=$(pwd)/.gradle
- export JAVA_HOME="/usr/bin/java"
- apt-get update -y && apt-get install wget -y  
@Nicolas,
I get the following error after following your suggestion
Skipping Git submodules setup
Executing "step_script" stage of the job script 00:01
$ export GRADLE_USER_HOME=$(pwd)/.gradle
$ export JAVA_HOME="/usr/bin/java"
$ apt-get update -y && apt-get install wget -y
Reading package lists...
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
W: Problem unlinking the file /var/cache/apt/pkgcache.bin - RemoveCaches (13: Permission denied)
W: Problem unlinking the file /var/cache/apt/srcpkgcache.bin - RemoveCaches (13: Permission denied)
$ echo "Compiling the code..."
Compiling the code...
$ chmod +x gradlew
$ ./gradlew build
ERROR: JAVA_HOME is set to an invalid directory: /usr/bin/java
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
Cleaning up project directory and file based variables 00:00
ERROR: Job failed: exit status 1

最新更新