Generating Android build with Gitlab CI

I've just written a blog post on how to setup Android builds in Gitlab CI using shared runners.

The quickest way would be to have a .gitlab-ci.yml with the following contents:

image: openjdk:8-jdk

variables:
  ANDROID_TARGET_SDK: "24"
  ANDROID_BUILD_TOOLS: "24.0.0"
  ANDROID_SDK_TOOLS: "24.4.1"

before_script:
  - apt-get --quiet update --yes
  - apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
  - wget --quiet --output-document=android-sdk.tgz https://dl.google.com/android/android-sdk_r${ANDROID_SDK_TOOLS}-linux.tgz
  - tar --extract --gzip --file=android-sdk.tgz
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter android-${ANDROID_TARGET_SDK}
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter platform-tools
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter build-tools-${ANDROID_BUILD_TOOLS}
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-android-m2repository
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-google-google_play_services
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-google-m2repository
  - export ANDROID_HOME=$PWD/android-sdk-linux
  - chmod +x ./gradlew

build:
  script:
    - ./gradlew assembleDebug
  artifacts:
    paths:
    - app/build/outputs/

This starts off using the Java 8 Docker image, then proceeds to download and install the necessary bits of the Android SDK before your build runs. My post also goes into detail as to how you can build this into a Docker image and host it on Gitlab itself.

Hopefully that helps!

UPDATE - 4/10/2017

I wrote the canonical blog post for setting up Android builds in Gitlab CI back in November '16 for the official Gitlab blog. Includes details on how to run tests and such as well. Linking here.

https://about.gitlab.com/2016/11/30/setting-up-gitlab-ci-for-android-projects/


You can add a build step to your GitLab CI project as below.

gradle assemble

enter image description here

This will generate debug and release APK's of the commit pushed at:

/build/outputs/apk/

You could then write a script to archive the generated APK's however you require.