17

I'd like to use GitLab CI system for my Android application gradle project. The project repository is hosted on GitLab.com, so I'd like to use one of the Shared Runners provided by Gitlab Inc.
While the official tutorial provides an example for NodeJS project runner configuration and there are also shared runners for Ruby projects, I couldn't find any example or even a runner that supports Android applications.

  • Is there a shared runner provided by GitLab.com, which supports Android projects out of the box (by specifying image: android:4.2.2 or something like this)?
  • Is there a way to configure existing shared runner provided by GitLab.com to support Android projects (by modifying the .gitlab-ci.yml file)?
JeB
  • 11,653
  • 10
  • 58
  • 87
  • you can choose the answer if your problem is solved, also it's can help each other with the same problem in the future. – Sucipto Sep 24 '16 at 19:43

3 Answers3

14

I'm using this docker image to run android build on gitlab-ci

Update:

Moved to Gitlab registry

image: registry.gitlab.com/showcheap/android-ci:latest

before_script:
    - export GRADLE_USER_HOME=`pwd`/.gradle
    - chmod +x ./gradlew

cache:
  paths:
     - .gradle/wrapper
     - .gradle/caches

build:
  stage: build
  script:
     - ./gradlew assemble

test:
  stage: test
  script:
     - ./gradlew check

Full Guide can check in this Gitlab Repository: https://gitlab.com/showcheap/android-ci

If your Target SDK and Build Tools version are not listed, please make a pull request or fork my repo then make your custom target and build version.

Sucipto
  • 817
  • 1
  • 8
  • 19
  • Thanks @Chip, you saved hours of my research. Can we use Docker image and Gitlab runners together. – Sanchit Jun 04 '16 at 14:27
  • @david yes, I've tested it on my project. let me know if you get some error. – Sucipto Oct 20 '16 at 02:45
  • @Sucipto I see, ok , So which is best? the former or the latter? – david Oct 20 '16 at 03:44
  • @david if you're use target sdk = 24, you should use latest image or specify image tag using `image: showcheap/gitlab-ci-android:24` – Sucipto Oct 20 '16 at 04:11
  • @Sucipto hey, nice work - I just started using your config and it works well. but I tought of an improvement: is it possible to push the `showcheap/gitlab-ci-android`-image to the gitlab container-registry for faster access? It seems that each build is downloading the image again and again from the docker-hub !? – hardysim Nov 26 '16 at 18:44
  • @hardysim Hi, thanks for your suggestion. I'll try to move from docker hub to gitlab registry. – Sucipto Nov 27 '16 at 02:51
  • 1
    @hardysim Hi, i just moved to gitlab registry. But when we triger android build, gitlab still downloading image again and again because gitlab ci runner and registry is on different machine. But i still moved to gitlab because auto build image on gitlab is faster than docker hub. – Sucipto Nov 28 '16 at 03:00
  • @Sucipto How can I build release build type? – kirtan403 Nov 28 '16 at 11:54
  • Hi @kirtan403, please take a look this answer http://stackoverflow.com/a/20927125/3086112 – Sucipto Nov 28 '16 at 13:39
  • @Sucipto Thanks for the answer! But I was asking for something different. To build an release type I need a keystore. As comitting a keystore to git is not recommended. (I have seen this in many discussions) So how can I build release type with gitlab CI? I am able to generate debug builds. But for release builds CI needs the keystore – kirtan403 Nov 28 '16 at 13:42
  • @kirtan403 since Gitlab provide free private repo, put Keystore on git is fine. You can store password in Gitlab variables https://gitlab.com/username/repo/variables – Sucipto Nov 29 '16 at 01:40
  • @Sucipto That's what I was thinking! Thanks for the update :) – kirtan403 Nov 29 '16 at 02:31
  • @Sucipto I think the reason why the runner is re-downloading the image all the time is that it's always a new runner. docker should cache images on each runner but as they use 100+ runners you'll always get to one which doesn't have the image already. – hardysim Dec 05 '16 at 10:20
  • I am getting this: ```Running with gitlab-ci-multi-runner 1.9.0-rc.1 (xxxx) Using Docker executor with image registry.gitlab.com/showcheap/android-ci:T25-B25.0.1 ... Using locally found image version with exactly the same ID Pulling docker image registry.gitlab.com/showcheap/android-ci:T25-B25.0.1 ... ERROR: Build failed: Error: image showcheap/android-ci not found``` – Roman Dec 15 '16 at 21:57
  • @Roman the image version for Target 25 doesn't exist. I just push new version for `T25-B25.0.1` (On progress) so you can use it from now (after build complete). – Sucipto Dec 16 '16 at 02:44
5

This is the .gitlab-ci.yml file which I'm using in my android project. Since I changed it to install one component at a time it is pretty stable. Sometimes the licence can't be accepted and the build fails. But that's a rare case. It is important that your build-tools are the same as in this script (build-tools-23.0.3) maybe you have to change the script here.

You can leave out the artifacts declaration I use it to get the lint report.

before_script:
  - apt-get --quiet update --yes
  - apt-get --quiet install --yes wget tar unzip openjdk-7-jdk lib32stdc++6 lib32z1
  - wget --quiet --output-document=android-sdk.tgz https://dl.google.com/android/android-sdk_r24.4.1-linux.tgz
  - tar --extract --gzip --file=android-sdk.tgz
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter android-23
  - 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-23.0.3
  - 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
  - wget --quiet --output-document=gradle.zip https://services.gradle.org/distributions/gradle-2.12-bin.zip
  - unzip -q gradle.zip
  - export ANDROID_HOME=$PWD/android-sdk-linux

build:
  script:
    - gradle-2.12/bin/gradle assembleDebug check --stacktrace
  artifacts:
    paths:
    - library/build/outputs/lint-results.html
    - app/build/outputs/lint-results.html
Kai
  • 38,985
  • 14
  • 88
  • 103
-1

UPDATE

According to this post you'll need to set up your own runner.

You'll find more information regarding building Android Apps on the same post.

Virtua Creative
  • 2,025
  • 1
  • 13
  • 18
  • Thanks for your answer, first of all. I'm afraid, however, it won't fit my case. You're talking here about setting up my own runner and I'd like to use one of the shared runners provided by Gitlab.com. – JeB Mar 20 '16 at 13:15