Updated 24 September 2023
GitLab is a tool that is used for software development. You can do the planning, code management, monitoring, bugs management etc. using a single tool. It also provides GitLab CI and CD which is Continuous Integration and Continuous Deployment respectively. With the help of a few configurations, your every commit or push triggers a CI pipeline. A pipeline is a group of jobs that get executed in stages. If everything goes right in a stage then only the pipeline moves to the next stage. There are stages like build, test and deploy.
In this blog, we will learn how to set up your Android project with GitLab CI so that with every push it automatically starts generating an APK. First, we need to generate the APK and then we will go for the deployment part in the other blog.
You are here to learn about the GitLab CI, So we assume that you already know how to upload your code on GitLab CI. In case you are not aware of that you can flow this link of the GitLab Doc.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
image: openjdk:8-jdk variables: ANDROID_COMPILE_SDK: "28" ANDROID_BUILD_TOOLS: "28.0.2" ANDROID_SDK_TOOLS: "4333796" before_script: - 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/sdk-tools-linux-${ANDROID_SDK_TOOLS}.zip - unzip -d android-sdk-linux android-sdk.zip - echo y | android-sdk-linux/tools/bin/sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null - echo y | android-sdk-linux/tools/bin/sdkmanager "platform-tools" >/dev/null - echo y | android-sdk-linux/tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}" >/dev/null - export ANDROID_HOME=$PWD/android-sdk-linux - export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/ - chmod +x ./gradlew # temporarily disable checking for EPIPE error and use yes to accept all licenses - set +o pipefail - yes | android-sdk-linux/tools/bin/sdkmanager --licenses - set -o pipefail stages: - build - test lintDebug: stage: build script: - ./gradlew -Pci --console=plain :app:lintDebug -PbuildDir=lint assembleDebug: stage: build script: - ./gradlew assembleDebug #./gradlew assembleRelease -Pandroid.injected.signing.store.file=$KEYFILE -Pandroid.injected.signing.store.password=$STORE_PASSWORD -Pandroid.injected.signing.key.alias=$KEY_ALIAS -Pandroid.injected.signing.key.password=$KEY_PASSWORD artifacts: paths: - mobikul/build/outputs/apk/ debugTests: stage: test script: - ./gradlew -Pci --console=plain :app:testDebug |
In the above code, We have defined two stages build and test. The build stage creates a debug APK (We can also change the command to generate release version APK) and checks for lint warnings. The second stage tests the APK.
1 2 3 |
git add .gitlab-ci.yml git commit -m "Added .gitlab-ci.yml" git push origin master |
Hope this helps you in getting started with GitLab CI. There are a lot more things that you can do with the GitLab and we will surely see them some other day.
That’s all for this blog. Thank you very much. This is Vedesh Kumar signing off.
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
2 comments
./gradlew assembleRelease -Pandroid.injected.signing.store.file=$KEYFILE -Pandroid.injected.signing.store.password=$STORE_PASSWORD -Pandroid.injected.signing.key.alias=$KEY_ALIAS -Pandroid.injected.signing.key.password=$KEY_PASSWORD
All you need is to define proper variables as mentioned in this line.