[FIXED] sdk location not found when running CI pipeline but build works locally

Issue

When I build this project locally using Gradle, I get a successful build. However, with this in my .yml file the build fails in the CI pipeline:

image: java:8-jdk

stages:
  - build
  - test
  - code-analysis

before_script:
  #  - echo `pwd` # debug
  #  - echo "$CI_BUILD_NAME, $CI_COMMIT_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

This is what the error message, in the build stage of he pipeline says:

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.

How do I fix this? Do I need to set the sdk location globally? Do I need to clear the cache? If so how do I achieve this in the .yml file?

Solution

Right now you are using the java-8 jdk image and this doesn’t has the android sdk installed. There are two ways to have a docker image with everything needed installed in it:

  • you create our own docker image
  • you use an open source docker image

The fastest way to solve your current issue would be replacing image: java:8-jdk with image: javiersantos/android-ci:28.0.3

Answered By – user9955719

Answer Checked By – Willingham (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published