My first experience with continuous integration was using Bitbucket in combination with Jenkins. I was pretty happy with my setup. Jenkins would run on every commit making sure my code compiles, run android lint and run my unit tests. I also set up continuous deployment using Fabric.
Now, at work, we use GitLab as a code repository. GitLab also offers continuous integration. When we decided to start using continuous integration at work we decided to give GitLab a chance. It was already integrated with GitLab and to use it we just needed to install a runner.
Using CI with GitLab is simple, after you install a runner you need to add a .gitlab-ci.yml file at the root of the repository. GitLab even offers template .gitlab-ci.yml files for various languages and frameworks. The android template is based on this blog post from 2016. It is a great guide but unfortunately today it doesn’t work. Google introduced a few changes in the command line tools.
Installing Android SDK
To install the Android SDK on a CI we need to install the command line tools (scroll to the bottom to Get just the command line tools). The command line tools include the sdkmanager - a command line tool that allows you to view, install, update, and uninstall packages for the Android SDK. So instead of
we can use
to download and install the Android SDK tools.
There is also an improvement in accepting licenses for the Android SDK. After you accept the licenses on your development machine the tools will generate a licenses folder in the Android SDK root directory. You can transfer the licenses from your development machine to your CI server. To accept the licenses we can use:
This will create a folder licenses with two files inside. The values written in the files are from my local machine. Depending on which components you use there might be other files on your machine like license for Google TV or Google Glass. Once the licenses are accepted we can install packages:
A sample project based on the Android Testing codelab with the full .gitlab-ci.yaml file can be found here. The rest of the script for building and unit testing is the same as the original post. The latest x86 emulator requires hardware acceleration to run so I’ll skip the functional tests for now.