Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating Android build with Gitlab CI

Tags:

I just installed Gitlab as repository for my projects and I want to take advantages of their Gitlab CI system. I want to automatically generate a distribution and debug Apk after each commit. I googled but I didn't find anything as a tutorial or similar cases. If someone could guide me in some way, it would be great.

Thanks!

like image 509
ares1986 Avatar asked Jul 24 '14 19:07

ares1986


People also ask

Does GitLab have Android app?

I don't think it's actually necessary. I mean I have the Github app installed - and I think I've used it maybe once and it wasn't all that helpful...

Why GitLab CI is better than Jenkins?

Both Jenkins and Gitlab are designed to serve different requirements. While Jenkins boasts of a large plugin shelf, Gitlab is a comprehensive DevOps tool. While multiple plugins do your job efficiently, integration and management of these plugins might become a challenge when the project scales up.

What can you do with GitLab CI?

Make software delivery repeatable and on-demand. GitLab Continuous Integration and Delivery automates all the steps required to build, test and deploy your code to your production environment. Continuous integration automates the builds, provides feedback via code review, and automates code quality and security tests.

Is GitLab a build automation tool?

GitLab provides Auto DevOps, which are prescribed out-of-the-box CI/CD templates that auto-discover the source code you have. Based on best practices, they automatically detect, build, test, deploy, and monitor your applications.


2 Answers

I've just written a blog post on how to setup Android builds in Gitlab CI using shared runners.

The quickest way would be to have a .gitlab-ci.yml with the following contents:

image: openjdk:8-jdk  variables:   ANDROID_TARGET_SDK: "24"   ANDROID_BUILD_TOOLS: "24.0.0"   ANDROID_SDK_TOOLS: "24.4.1"  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_r${ANDROID_SDK_TOOLS}-linux.tgz   - tar --extract --gzip --file=android-sdk.tgz   - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter android-${ANDROID_TARGET_SDK}   - 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-${ANDROID_BUILD_TOOLS}   - 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 +x ./gradlew  build:   script:     - ./gradlew assembleDebug   artifacts:     paths:     - app/build/outputs/ 

This starts off using the Java 8 Docker image, then proceeds to download and install the necessary bits of the Android SDK before your build runs. My post also goes into detail as to how you can build this into a Docker image and host it on Gitlab itself.

Hopefully that helps!

UPDATE - 4/10/2017

I wrote the canonical blog post for setting up Android builds in Gitlab CI back in November '16 for the official Gitlab blog. Includes details on how to run tests and such as well. Linking here.

https://about.gitlab.com/2016/11/30/setting-up-gitlab-ci-for-android-projects/

like image 171
Greyson Parrelli Avatar answered Oct 18 '22 21:10

Greyson Parrelli


You can add a build step to your GitLab CI project as below.

gradle assemble 

enter image description here

This will generate debug and release APK's of the commit pushed at:

/build/outputs/apk/ 

You could then write a script to archive the generated APK's however you require.

like image 41
Jonathon Fry Avatar answered Oct 18 '22 21:10

Jonathon Fry