1# To contribute improvements to CI/CD templates, please follow the Development guide at:
2# https://docs.gitlab.com/ee/development/cicd/templates.html
3# This specific template is located at:
4# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Android.gitlab-ci.yml
5
6# Read more about this script on this blog post https://about.gitlab.com/2018/10/24/setting-up-gitlab-ci-for-android-projects/, by Jason Lenny
7# If you are interested in using Android with FastLane for publishing take a look at the Android-Fastlane template.
8
9image: openjdk:11-jdk
10
11variables:
12
13  # ANDROID_COMPILE_SDK is the version of Android you're compiling with.
14  # It should match compileSdkVersion.
15  ANDROID_COMPILE_SDK: "30"
16
17  # ANDROID_BUILD_TOOLS is the version of the Android build tools you are using.
18  # It should match buildToolsVersion.
19  ANDROID_BUILD_TOOLS: "30.0.3"
20
21  # It's what version of the command line tools we're going to download from the official site.
22  # Official Site-> https://developer.android.com/studio/index.html
23  # There, look down below at the cli tools only, sdk tools package is of format:
24  #        commandlinetools-os_type-ANDROID_SDK_TOOLS_latest.zip
25  # when the script was last modified for latest compileSdkVersion, it was which is written down below
26  ANDROID_SDK_TOOLS: "7583922"
27
28# Packages installation before running script
29before_script:
30  - apt-get --quiet update --yes
31  - apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
32
33  # Setup path as ANDROID_SDK_ROOT for moving/exporting the downloaded sdk into it
34  - export ANDROID_SDK_ROOT="${PWD}/android-home"
35  # Create a new directory at specified location
36  - install -d $ANDROID_SDK_ROOT
37  # Here we are installing androidSDK tools from official source,
38  # (the key thing here is the url from where you are downloading these sdk tool for command line, so please do note this url pattern there and here as well)
39  # after that unzipping those tools and
40  # then running a series of SDK manager commands to install necessary android SDK packages that'll allow the app to build
41  - wget --output-document=$ANDROID_SDK_ROOT/cmdline-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}_latest.zip
42  # move to the archive at ANDROID_SDK_ROOT
43  - pushd $ANDROID_SDK_ROOT
44  - unzip -d cmdline-tools cmdline-tools.zip
45  - pushd cmdline-tools
46  # since commandline tools version 7583922 the root folder is named "cmdline-tools" so we rename it if necessary
47  - mv cmdline-tools tools || true
48  - popd
49  - popd
50  - export PATH=$PATH:${ANDROID_SDK_ROOT}/cmdline-tools/tools/bin/
51
52  # Nothing fancy here, just checking sdkManager version
53  - sdkmanager --version
54
55  # use yes to accept all licenses
56  - yes | sdkmanager --licenses || true
57  - sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}"
58  - sdkmanager "platform-tools"
59  - sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}"
60
61  # Not necessary, but just for surity
62  - chmod +x ./gradlew
63
64# Basic android and gradle stuff
65# Check linting
66lintDebug:
67  interruptible: true
68  stage: build
69  script:
70    - ./gradlew -Pci --console=plain :app:lintDebug -PbuildDir=lint
71
72# Make Project
73assembleDebug:
74  interruptible: true
75  stage: build
76  script:
77    - ./gradlew assembleDebug
78  artifacts:
79    paths:
80      - app/build/outputs/
81
82# Run all tests, if any fails, interrupt the pipeline(fail it)
83debugTests:
84  interruptible: true
85  stage: test
86  script:
87    - ./gradlew -Pci --console=plain :app:testDebug
88