GitLab Runner (CI) and Android

1. GitLab Runner

GitLab is a nice tool to manage your git projects. It is like Github, but you can install the Community Edition (CE) version on your own server.
GitLab can build your projects automatically by using so-called „runners“. In this short tutorial I want to show you, how you can use GitLab runners with the Android SDK to build your Android projects automatically on your server.

2. Install and register gitlab-runner

First you should install gitlab-runner on your server if you have not done it already.
Install them how shown in the documentation from GitLab. Afterwards register the runner with GitLab. Navigate to the runners section in the GitLab administration panel and copy the token.
Afterwards enter the following command:

3. Android SDK

To build Android projects on your server, you need to install the Android SDK. At first install the necessary dependencies:

Afterwards download the current Android SDK (you can check the Android developer’s website for new version) and extract it:

In order to build the apps, you must download the needed SDK platforms and tools. To install ALL default plattforms (in my case 8, 10, and 15-23), use the following command:

To filter packages you want to install, fetch a list of available packages and install them by number:

({n} can be replaced by multiple numbers – comma seperated)

4. Preparing

If you have multiple projects with the same gradle version, we can use a shared folder for them. Create a new folder and set user and group to gitlab-runner:

Edit /home/gitlab-runner/.profile and add

So we don’t need to define this variables per project in gitlab.

5. Your project

To automatically build the project by the server, we need to make some small changes.

Create a file with the name .gitlab-ci.yml in the root folder of your project with following content:

Additionally you should add following lines to your build.gradle files of your modules, to avoid abort due to Lint errors:

6. Commit and push

Commit your changes and push them. The runner should now automatically build the project. More information about gitlab continous integration are available here.

GitLab Runner

  • David Montecillo

    I always got file not found. when updating sdk or whenever i used the android-sdk-linux/tools/android. all are file not found.