Kategorien
Android

Configuration for Gitlab CI Android projects

Hey everyone,

I just recently wanted to give Gitlab CI a try. It is the CI part of the Gitlab hosting solution. They just recently announced that you can use their shared runners that they are now running on DigitalOcean’s servers for free!

So I currently have an Android project that I want to have built on one their free shared runners. I wasn’t able to find a straight forward solution for a .gitlab-ci.yml  file that works for Android projects.

So, this is what I now successfully use for building my Android project on Gitlab CI’s free shared runners:

image: java:openjdk-8-jdk

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_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.2
  - 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 u+x ./gradlew

build:
  script:
    - ./gradlew assemble lint
  artifacts:
    paths:
    - app/build/outputs/

Let’s analyse it:

At first we have image: java:openjdk-8-jdk . This instructs Gitlab CI to load a Docker image with OpenJDK 8 configured. This is because I make use of RetroLambda -> we need Java 8.

Next we update the system via apt-get and install some dependecies.

Next we download and unzip the current Android SDK.

Once unzipped, we can use the Android SDK Manager to install all of our needed Android SDK components.

Next we need to set the ANDROID_HOME environment variable.

Finally, we need to make the Gradle Wrapper script executable.

Then in the script: block, we define the actual command that will be executed. Here we can also add tests etc (you know the Gradle commands available…)

And that’s it. Now, whenever you push new commits to your repository, Gitlab will automatically perform a build on Gitlab CI’s free shared runners hosted on DigitalOcean.

After a successful build, we set the archives/files that we want to save for later download. Which, in this case, are just all file in the build/outputs/ folder. That includes Lint results, APKs, etc…

 

I hope this helps a lot of Android devs to setup their Android projects with Gitlab-CI

2 Antworten auf „Configuration for Gitlab CI Android projects“

Hi. Thanks for this tutorial, it helps me a lot. But I have a problem building my code. Could you take an eye on the log I have??

####################################
:theme:preBuild FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ‚:theme:preBuild‘.
> failed to find target android-21 : /builds/xphnx/twelf_cm12_theme/android-sdk-linux

* Try:
Run with –stacktrace option to get the stack trace. Run with –info or –debug option to get more log output.

BUILD FAILED

Total time: 24.464 secs

ERROR: Build failed: exit code 1
#####################################

My repo is https://gitlab.com/xphnx/twelf_cm12_theme

Any idea for solving it?? I have googling a little but I didnt find any solution.

Sorry!. Fixed changing this into build.gradle

compileSdkVersion 21
buildToolsVersion „21.1.2“

targetSdkVersion 21 <—- targetSdkVersion 23

Kommentar verfassen

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.