Git lab pipeline Android project - android

I create an android project in git lab. I'm trying to use pipelines .
The build failed with message
Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.
How can I accept this licences automatically?
Adding --no-ui --all is not enough (I have already tried to add them!).
I tried all the soluctions presented [here](you need to accept the license agreements and complete) with no success.
Does someone actually managed to make git lab pipelines works for android?
Below my .gitlab-ci.yml file.
image: openjdk:8-jdk
variables:
ANDROID_COMPILE_SDK: "24"
ANDROID_BUILD_TOOLS: "25.0.3"
ANDROID_SDK_TOOLS: "25.0.3"
before_script:
- export ANDROID_HOME=$PWD/
- export PATH=$PATH:$PWD/
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/tools_r${ANDROID_SDK_TOOLS}-linux.zip
- unzip android-sdk.zip
- echo y | tools/android --silent update sdk --no-ui --all --filter android-${ANDROID_COMPILE_SDK}
- echo y | tools/android --silent update sdk --no-ui --all --filter platform-tools
- echo y | tools/android --silent update sdk --no-ui --all --filter build-tools-${ANDROID_BUILD_TOOLS}
- echo y | tools/android --silent update sdk --no-ui --all --filter extra-android-m2repository
- echo y | tools/android --silent update sdk --no-ui --all --filter extra-google-google_play_services
- echo y | tools/android --silent update sdk --no-ui --all --filter extra-google-m2repository
- chmod +x ./gradlew
stages:
- build
build:
stage: build
script:
- ./gradlew assembleDebug --stacktrace
artifacts:
paths:
- app/build/outputs/

The sdkmanager cli can be used to update sdks/ accept licenses.
To accept all licenses you can run
echo y | tools/bin/sdkmanager --licenses

I finnally resolve the problem using sdkmanager but I had to download the sdk zip instead of the tools zip like the code in my original question.
This is the final code I copied from Nick Petrovsky post on gitlab issue tracker
image: openjdk:8-jdk
variables:
ANDROID_COMPILE_SDK: "24"
ANDROID_BUILD_TOOLS: "25.0.3"
# ANDROID_SDK_TOOLS: "25.0.3"
ANDROID_SDK_TOOLS_REV: "3859397" # "26.0.1"
before_script:
- mkdir $HOME/.android # For sdkmanager configs
- echo 'count=0' > $HOME/.android/repositories.cfg # Avoid warning
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-${ANDROID_SDK_TOOLS_REV}.zip
- mkdir $PWD/android-sdk-linux
- unzip -qq android-sdk.zip -d $PWD/android-sdk-linux
- export ANDROID_HOME=$PWD/android-sdk-linux
- export ANDROID_NDK_HOME=$ANDROID_HOME/ndk-bundle # Remove if you don't need NDK
- export PATH=$PATH:$ANDROID_HOME/platform-tools/:$ANDROID_NDK_HOME
- echo y | $ANDROID_HOME/tools/bin/sdkmanager --update
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'tools'
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'platform-tools'
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'build-tools;'$ANDROID_BUILD_TOOLS
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'platforms;android-'$ANDROID_COMPILE_SDK
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'extras;android;m2repository'
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'extras;google;google_play_services'
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'extras;google;m2repository'
- chmod +x ./gradlew

At the end I used this gitlab-ci-android docker image
It is faster and cause much less problems:
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
- mkdir -p $GRADLE_USER_HOME
- chmod +x ./gradlew
cache:
paths:
- .gradle/wrapper
- .gradle/caches
build:
stage: build
script:
- ./gradlew assemble
test:
stage: test
script:
- ./gradlew check

I have created a CI image for Android, which can be found at https://gitlab.com/mvglasow/android-gitlab-ci.
It is based on what is described at https://about.gitlab.com/2018/10/24/setting-up-gitlab-ci-for-android-projects/, but it has all the Android tools in the image already so you don’t have to install them again for every CI run. Compared to the instructions, the image saves you about 30 seconds per pipeline.

Related

How to generate a signed release APK with Gitlab CI/CD?

I am experimenting with GitLab's CI/CD and is figuring out how to generate a signed release APK.
I've read this article here.
and it suggested the following:
- ./gradlew assembleRelease
-Pandroid.injected.signing.store.file=$(pwd)/my.keystore
-Pandroid.injected.signing.store.password=$KEYSTORE_PASSWORD
-Pandroid.injected.signing.key.alias=$KEY_ALIAS
-Pandroid.injected.signing.key.password=$KEY_PASSWORD
and storing the variables at Gitlab CI/CD variables.
But everytime I run the pipeline it always results to this:
* What went wrong:
Execution failed for task ':app:packageRelease'.
> 1 exception was raised by workers:
java.lang.RuntimeException: java.lang.RuntimeException:
com.android.ide.common.signing.KeytoolException: Failed to read key key0 from store "/tmp/Lp7GrQLJ/0/XXXXX/sample-android-project/keystore": Keystore was tampered with, or password was incorrect
Can anyone please guide me here? What could I possible be doing wrong?
May this will helps you.
image: openjdk:8-jdk
variables:
ANDROID_COMPILE_SDK: "27"
ANDROID_BUILD_TOOLS: "27.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_COMPILE_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
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
- export GRADLE_USER_HOME="$(pwd)/.gradle"
- export ANDROID_HOME="$(pwd)/.android"
- mkdir -p "${ANDROID_HOME}/licenses"
- echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55\nd56f5187479451eabf01fb78af6dfcb131a6481e" > "${ANDROID_HOME}/licenses/android-sdk-license"
- echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "${ANDROID_HOME}/licenses/android-sdk-preview-license"
- echo -e "\nd975f751698a77b662f1254ddbeed3901e976f5a" > "${ANDROID_HOME}/licenses/intel-android-extra-license"
#- ./gradlew --parallel --stacktrace --no-daemon build
- chmod +x ./gradlew
stages:
- build
build:
stage: build
script:
- ./gradlew assembleDebug
artifacts:
paths:
- app/build/outputs/
This code is for the Debug Build please replace the assembleDebug to assembleRelease in script.
Put it in your project main folder with the name .gitlab-ci.yml.

gitlab pipelines configure the gitlab-ci.yml file

I work in Android Project, I use gitlab.
I config gitlab-ci.yml file and I try to commit my Android Project but i have an issue in the gitLab pipeline.
I migrating my code and i'm trying to build my application but I receive erro below:
FAILURE: Build failed with an exception.
What went wrong:
A problem occurred configuring project ':app'.
You have not accepted the license agreements of the following SDK components:
[ConstraintLayout for Android 1.0.2, Solver for ConstraintLayout 1.0.2].
Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.
Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d.android.com/r/studio-ui/export-licenses.html
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: 2 mins 8.129 secs
ERROR: Job failed: exit code 1
this is my gitlab-ci.yml file
image: openjdk:8-jdk
variables:
ANDROID_COMPILE_SDK: "25"
ANDROID_BUILD_TOOLS: "25.0.2"
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_COMPILE_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
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
- chmod +x ./gradlew
stages:
- build
- test
build:
stage: build
script:
- ./gradlew assembleDebug
artifacts:
paths:
- app/build/outputs/
unitTests:
stage: test
script:
- ./gradlew test
functionalTests:
stage: test
script:
- wget --quiet --output-document=android-wait-for-emulator https://raw.githubusercontent.com/travis-ci/travis-cookbooks/0f497eb71291b52a703143c5cd63a217c8766dc9/community-cookbooks/android-sdk/files/default/android-wait-for-emulator
- chmod +x android-wait-for-emulator
- echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter sys-img-x86-google_apis-${ANDROID_COMPILE_SDK}
- echo no | android-sdk-linux/tools/android create avd -n test -t android-${ANDROID_COMPILE_SDK} --abi google_apis/x86
- android-sdk-linux/tools/emulator64-x86 -avd test -no-window -no-audio &
- android update sdk --no-ui --filter build-tools-25.0.2,android-25,extra-android-m2repository
- ./android-wait-for-emulator
- adb shell input keyevent 82
- ./gradlew cAT
artifacts:
paths:
- app/build/reports/androidTests/
add the following lines to end of before_script section
- export SDK_MANAGER="${ANDROID_HOME}/tools/bin/sdkmanager --sdk_root=${ANDROID_HOME}"
- set +o pipefail
- echo y | ${SDK_MANAGER} --licenses
- set -o pipefail
a full before_script might looks like this
variables:
ANDROID_COMPILE_SDK: "28"
ANDROID_BUILD_TOOLS: "28.0.3"
ANDROID_SDK_TOOLS: "6609375_latest"
before_script:
- echo ANDROID_COMPILE_SDK ${ANDROID_COMPILE_SDK}
- echo ANDROID_BUILD_TOOLS ${ANDROID_BUILD_TOOLS}
- echo ANDROID_SDK_TOOLS ${ANDROID_SDK_TOOLS}
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}.zip
- unzip -d android-sdk-linux android-sdk.zip
- export ANDROID_SDK_ROOT=$PWD/android-sdk-linux
- export SDK_MANAGER="${ANDROID_SDK_ROOT}/tools/bin/sdkmanager --sdk_root=${ANDROID_SDK_ROOT}"
- echo y | ${SDK_MANAGER} "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null
- echo y | ${SDK_MANAGER} "platform-tools" >/dev/null
- echo y | ${SDK_MANAGER} "build-tools;${ANDROID_BUILD_TOOLS}" >/dev/null
- export PATH=$PATH:${ANDROID_SDK_ROOT}/platform-tools/
- chmod +x ./gradlew
# temporarily disable checking for EPIPE error and use yes to accept all licenses
- set +o pipefail
- echo y | ${SDK_MANAGER} --licenses
- set -o pipefail

Unable to run an Android application in a Docker container with Gitlab-CI

I've been struggling with a problem for a couple of days now and I hope somebody will be able to help me...
I try to use gitlab ci for my basic android application project.
Based on the following tutorial Setting up GitLab CI for Android projects, I wrote a .gitlab-ci.yml script :
image: openjdk:8-jdk
variables:
ANDROID_COMPILE_SDK: "25"
ANDROID_BUILD_TOOLS: "25.0.1"
ANDROID_SDK_TOOLS: "25.2.3"
before_script:
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1 libqt5widgets5
- wget --quiet --output-document=tools.zip https://dl.google.com/android/repository/tools_r${ANDROID_SDK_TOOLS}-linux.zip
- unzip tools.zip -d /sdk
- rm tools.zip
- echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter android-${ANDROID_COMPILE_SDK}
- echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter platform-tools
- echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter build-tools-${ANDROID_BUILD_TOOLS}
- echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter extra-android-m2repository
- echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter extra-google-google_play_services
- echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter extra-google-m2repository
- export ANDROID_HOME=/sdk
- export PATH=$PATH:$ANDROID_HOME/platform-tools/
- chmod +x ./gradlew
stages:
- test
functionalTests:
stage: test
script:
- echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter sys-img-x86-google_apis-${ANDROID_COMPILE_SDK}
- echo no | /sdk/tools/android create avd -n test -t android-${ANDROID_COMPILE_SDK} --abi google_apis/x86
- /sdk/tools/emulator64-x86 -avd test -no-accel -no-window -no-audio &
- adb wait-for-device
- ./gradlew assembleDebug
- ./gradlew assembleDebugAndroidTest
- adb devices
- adb shell service list
- adb shell input keyevent 82 # Unlock device to allow install...
- adb install -r app/build/outputs/apk/app-debug.apk
- adb install -r app/build/outputs/apk/app-debug-androidTest.apk
- adb shell am instrument -w -r -e debug false -e class com.example.myfirstapp.ManageItemListTest com.example.myfirstapp.test/android.support.test.runner.AndroidJUnitRunner
artifacts:
paths:
- app/build/outputs/
My first difficulty - as somebody mentioned in the tutorial's comments - is that I have no way to manage and enable hardware acceleration in a docker container.
For now, I added the '-no-accel' option when lauching the AVD to get the script further executed.
But the main problem is that 'adb shell input keyevent 82' as well as the following installation commands fail.
The emulated device is running but is apparently missing lots of services as shown below :
Found 17 services:
0 media.camera: [android.hardware.ICameraService]
1 media.resource_manager: [android.media.IResourceManagerService]
2 media.player: [android.media.IMediaPlayerService]
3 media.sound_trigger_hw: [android.hardware.ISoundTriggerHwService]
4 media.radio: [android.hardware.IRadioService]
5 media.audio_policy: [android.media.IAudioPolicyService]
6 media.drm: [android.media.IMediaDrmService]
7 media.extractor: [android.media.IMediaExtractorService]
8 media.audio_flinger: [android.media.IAudioFlinger]
9 drm.drmManager: [drm.IDrmManagerService]
10 media.codec: [android.media.IMediaCodecService]
11 gpu: [android.ui.IGpuService]
12 SurfaceFlinger: [android.ui.ISurfaceComposer]
13 android.service.gatekeeper.IGateKeeperService: []
14 android.security.keystore: [android.security.IKeystoreService]
15 android.hardware.fingerprint.IFingerprintDaemon: []
16 batteryproperties: [android.os.IBatteryPropertiesRegistrar]
Only 17 services are started when 91 do actually run for an AVD locally launched on my desktop with Android Studio.
The package manager (package: [android.content.pm.IPackageManager]) is among the missing services...
Can anybody tell me what happens and what to do ?
Kind regards,
Laurent
I finally found a solution using an ARM system image.
But one must also wait for all required services to start.
Hereafter is the new script for anyone interested:
image: openjdk:8-jdk
variables:
ANDROID_COMPILE_SDK: "25"
ANDROID_BUILD_TOOLS: "25.0.1"
ANDROID_SDK_TOOLS: "25.2.3"
before_script:
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1 libqt5widgets5
- wget --quiet --output-document=tools.zip https://dl.google.com/android/repository/tools_r${ANDROID_SDK_TOOLS}-linux.zip
- unzip tools.zip -d /sdk
- rm tools.zip
- echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter android-${ANDROID_COMPILE_SDK}
- echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter platform-tools
- echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter build-tools-${ANDROID_BUILD_TOOLS}
- echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter extra-android-m2repository
- echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter extra-google-google_play_services
- echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter extra-google-m2repository
- export ANDROID_HOME=/sdk
- export PATH=$PATH:$ANDROID_HOME/platform-tools/
- chmod +x ./gradlew
stages:
- test
functionalTests:
stage: test
script:
- echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter sys-img-armeabi-v7a-google_apis-${ANDROID_COMPILE_SDK}
- echo no | /sdk/tools/android create avd -n test -t android-${ANDROID_COMPILE_SDK} --abi google_apis/armeabi-v7a
- /sdk/tools/emulator64-arm -avd test -no-audio -gpu off -no-boot-anim -no-window &
- adb wait-for-device
- OUT=`adb shell service list | grep IPackageManager 2>&1 &` # Now wait for other services startup
- until [[ $OUT =~ .*IPackageManager.* ]]; do
- sleep 20
- OUT=`adb shell service list | grep IPackageManager 2>&1 &`
- done
- ./gradlew assembleDebug
- ./gradlew assembleDebugAndroidTest
- adb shell input keyevent 82 # Unlock device to allow install...
- adb install -r app/build/outputs/apk/app-debug.apk
- adb install -r app/build/outputs/apk/app-debug-androidTest.apk
- adb shell am instrument -w -r -e debug false -e class com.example.myfirstapp.ManageItemListTest com.example.myfirstapp.test/android.support.test.runner.AndroidJUnitRunner
artifacts:
paths:
- app/build/outputs/
For this basic example, the whole execution took more than 25 minutes to complete (with my test failing but that's another story... ;-)).
It would be great to have hardware acceleration...
Kind regards,
Laurent
If you edit the gitlab runner .toml file and set "privileged:" to true, then you should be able to use hardware acceleration with the emulator.
This way you no longer have to use unsupported ARM images and instead can use intel images.

How to accept android library licenses automatically from command line?

I am using gitlab-ci to build my android project. After lots of searching I found how to accept sdk licences. But I am getting licence not accepted error on ConstraintLayout library. Here is my .gitlab-ci.yml:
image: openjdk:8-jdk
variables:
ANDROID_TARGET_SDK: "25"
ANDROID_BUILD_TOOLS: "25.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
- chmod +x ./copy_licenses.sh
build:
script:
- ./copy_licenses.sh
- ./gradlew assembleDebug
artifacts:
paths:
- app/build/outputs/
I copyed my licence files to the $ANDROID_HOME/licenses with copy_licenses.sh :
#!/bin/bash
# fail if any commands fails
set -e
# debug log
set -x
cp -a "./android-licenses" "$ANDROID_HOME/licenses"
after executing this, I am getting this error:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> You have not accepted the license agreements of the following SDK components:
[Solver for ConstraintLayout 1.0.0-beta4, ConstraintLayout for Android 1.0.0-beta4].
Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.
Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d.android.com/r/studio-ui/export-licenses.html
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
How to accept ConstraintLayout 1.0.0-beta4 licence from command line?
in my case helped adding before_script: part:
- mkdir -p "${ANDROID_HOME}/licenses"
- echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "${ANDROID_HOME}/licenses/android-sdk-license"
- echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "${ANDROID_HOME}/licenses/android-sdk-preview-license"
- echo -e "\nd975f751698a77b662f1254ddbeed3901e976f5a" > "${ANDROID_HOME}/licenses/intel-android-extra-license"
Try while true; do echo "y"; sleep 1;done instead of echo y

Generating Android build with Gitlab CI

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!
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/
You can add a build step to your GitLab CI project as below.
gradle assemble
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.

Categories

Resources