运行 CI 管道时找不到 sdk 位置,但在本地构建工作
sdk location not found when running CI pipeline but build works locally
当我使用 Gradle 在本地构建此项目时,我获得了成功的构建。但是,在我的 .yml 文件中,构建在 CI 管道中失败:
image: java:8-jdk
stages:
- build
- test
- code-analysis
before_script:
# - echo `pwd` # debug
# - echo "$CI_BUILD_NAME, $CI_BUILD_REF_NAME $CI_BUILD_STAGE" # debug
- export GRADLE_USER_HOME=`pwd`/.gradle
- chmod +x gradlew
cache:
paths:
- .gradle/wrapper
- .gradle/caches
build:
stage: build
script:
- ./gradlew clean build
test:
stage: test
script:
- ./gradlew test
lint:
stage: code-analysis
script:
./gradlew lint
checkstyle:
stage: code-analysis
script:
./gradlew checkstyle
pmd:
stage: code-analysis
script:
./gradlew pmd
这是管道构建阶段的错误消息:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:assemble'.
> Could not create task ':app:assembleRelease'.
> Could not create task ':app:lintVitalRelease'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file.
我该如何解决这个问题?需要全局设置sdk位置吗?我需要清除缓存吗?如果是这样,我如何在 .yml 文件中实现这一点?
现在您使用的是 java-8 jdk 图像,并且没有安装 android sdk。有两种方法可以得到一个 docker 图像,里面安装了所有需要的东西:
- 您创建我们自己的 docker 图像
- 您使用了开源 docker 图片
解决您当前问题的最快方法是将 image: java:8-jdk
替换为 image: javiersantos/android-ci:28.0.3
当我使用 Gradle 在本地构建此项目时,我获得了成功的构建。但是,在我的 .yml 文件中,构建在 CI 管道中失败:
image: java:8-jdk
stages:
- build
- test
- code-analysis
before_script:
# - echo `pwd` # debug
# - echo "$CI_BUILD_NAME, $CI_BUILD_REF_NAME $CI_BUILD_STAGE" # debug
- export GRADLE_USER_HOME=`pwd`/.gradle
- chmod +x gradlew
cache:
paths:
- .gradle/wrapper
- .gradle/caches
build:
stage: build
script:
- ./gradlew clean build
test:
stage: test
script:
- ./gradlew test
lint:
stage: code-analysis
script:
./gradlew lint
checkstyle:
stage: code-analysis
script:
./gradlew checkstyle
pmd:
stage: code-analysis
script:
./gradlew pmd
这是管道构建阶段的错误消息:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:assemble'.
> Could not create task ':app:assembleRelease'.
> Could not create task ':app:lintVitalRelease'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file.
我该如何解决这个问题?需要全局设置sdk位置吗?我需要清除缓存吗?如果是这样,我如何在 .yml 文件中实现这一点?
现在您使用的是 java-8 jdk 图像,并且没有安装 android sdk。有两种方法可以得到一个 docker 图像,里面安装了所有需要的东西:
- 您创建我们自己的 docker 图像
- 您使用了开源 docker 图片
解决您当前问题的最快方法是将 image: java:8-jdk
替换为 image: javiersantos/android-ci:28.0.3