How to test and build your Android applications using Gitlab CI

Could be a guest post of the people involved with the Unofficial GitLab client for Android,

https://gitlab.com/u/Michi302 seems to contribute to CE also.

# Notes

Objective

Most people understand the benefits of continuous integration, but setting it up for Android can be a hassle. This article will outline setting up and running tests on an Android Studio project with Gradle on Gitlab's CI

  • Learn how to setup an Android build on Gitlab's CI
  • Learn how to run UI (Expresso) tests on an emulator

Outline

Setting up the Android Project for testing

Setting up the CI environment.

  • Using an Ubuntu runner, similar to the iOS post
  • Setup any Android specific stuff.

Get the project to build

  • How to save the APK as an artifact (This should probably be after the tests pass right?)

Get the JUnit tests to run

  • Pretty straight forward, just a gradle invocation.

Get the UI (Expresso) tests to run.

  • This is the tricky part! Getting an emulator running in a CI environment is non-trivial.
  • We'll then setup this travis script to start an emulator.

Next Steps (Covered in another post)

  • Speed up builds using a precompiled docker image with the build environment
  • Publish to Google Play using this gradle plugin