{"id":18421155,"url":"https://github.com/akarsh/android-ci-tutorial-for-docker-and-gitlab","last_synced_at":"2025-04-13T11:59:12.447Z","repository":{"id":159217560,"uuid":"113560920","full_name":"akarsh/Android-CI-tutorial-for-Docker-and-GitLab","owner":"akarsh","description":"The projects presents Android CI tutorial covering Docker and GitLab","archived":false,"fork":false,"pushed_at":"2017-12-18T11:13:41.000Z","size":1065,"stargazers_count":7,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-13T11:59:08.339Z","etag":null,"topics":["dockerfile","gitlab-ci"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akarsh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-08T10:11:11.000Z","updated_at":"2025-02-28T18:05:40.000Z","dependencies_parsed_at":"2023-06-06T09:45:57.747Z","dependency_job_id":null,"html_url":"https://github.com/akarsh/Android-CI-tutorial-for-Docker-and-GitLab","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akarsh%2FAndroid-CI-tutorial-for-Docker-and-GitLab","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akarsh%2FAndroid-CI-tutorial-for-Docker-and-GitLab/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akarsh%2FAndroid-CI-tutorial-for-Docker-and-GitLab/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akarsh%2FAndroid-CI-tutorial-for-Docker-and-GitLab/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akarsh","download_url":"https://codeload.github.com/akarsh/Android-CI-tutorial-for-Docker-and-GitLab/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248710434,"owners_count":21149188,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dockerfile","gitlab-ci"],"created_at":"2024-11-06T04:24:33.591Z","updated_at":"2025-04-13T11:59:12.416Z","avatar_url":"https://github.com/akarsh.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Android CI tutorial for Docker and GitLab\n\nThe projects presents Android CI tutorial covering Docker and GitLab\n\n- [Android CI tutorial for Docker and GitLab](#android-ci-tutorial-for-docker-and-gitlab)\n    - [Scripts](#scripts)\n    - [Docker](#docker)\n    - [GitLab](#gitlab)\n        - [Tutorials](#tutorials)\n        - [References to Dockerfiles](#references-to-dockerfiles)\n\n## Scripts\n\nGitlab scripts - .gitlab-ci.yml\nAll the scripts are stored in the folder **GitLabCIScripts**\n\n## Docker\n\nGoal: To create a Docker image that contains the Android SDK command line tools installed in it.\n\n- Create a account in [Docker](https://www.docker.com/). Then go to [Docker hub](https://hub.docker.com).\n\n- Next, link your Github or Bitbucket account to your Docker account.\n\n![linking github account](./images/github-link-accounts.png)\n\n- Then, go to Github or Bitbucket to create a new repository that contains Docker file. Because, Docker currently supports only Github and Bitbucket for creating automation builds.\n\n![creating a project in Github](./images/github-project-creation.png)\n\n- After creating a repository in Github or Bitbucket. Create a new file. Name the file as\n\n        Dockerfile\n\n    without any extensions.\n\n![](./images/adding-dockerfile.png)\n\nHere is the code for Dockerfile\n\n```Docker\n#\n# GitLab CI: Android\n# Version: 1.0.0\n#\n# https://hub.docker.com/r/sakarsh/gitlab-ci-android-akarsh-seggemu/\n#\n\nFROM ubuntu:18.04\nMAINTAINER Akarsh Seggemu \u003csakarshkumar@gmail.com\u003e\n\nENV VERSION_SDK_TOOLS \"3859397\"\n\nENV ANDROID_HOME \"/sdk\"\nENV PATH \"$PATH:${ANDROID_HOME}/tools\"\nENV DEBIAN_FRONTEND noninteractive\n\nRUN apt-get -qq update \u0026\u0026 \\\n    apt-get install -qqy --no-install-recommends \\\n      bzip2 \\\n      curl \\\n      git-core \\\n      html2text \\\n      openjdk-8-jdk \\\n      libc6-i386 \\\n      lib32stdc++6 \\\n      lib32gcc1 \\\n      lib32ncurses5 \\\n      lib32z1 \\\n      unzip \\\n    \u0026\u0026 rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*\n\nRUN rm -f /etc/ssl/certs/java/cacerts; \\\n    /var/lib/dpkg/info/ca-certificates-java.postinst configure\n\nRUN curl -s https://dl.google.com/android/repository/sdk-tools-linux-${VERSION_SDK_TOOLS}.zip \u003e /sdk.zip \u0026\u0026 \\\n    unzip /sdk.zip -d /sdk \u0026\u0026 \\\n    rm -v /sdk.zip\n\nRUN mkdir -p $ANDROID_HOME/licenses/ \\\n  \u0026\u0026 echo \"8933bad161af4178b1185d1a37fbf41ea5269c55\\nd56f5187479451eabf01fb78af6dfcb131a6481e\" \u003e $ANDROID_HOME/licenses/android-sdk-license \\\n  \u0026\u0026 echo \"84831b9409646a918e30573bab4c9c91346d8abd\" \u003e $ANDROID_HOME/licenses/android-sdk-preview-license\n\nADD packages.txt /sdk\nRUN mkdir -p /root/.android \u0026\u0026 \\\n  touch /root/.android/repositories.cfg \u0026\u0026 \\\n  ${ANDROID_HOME}/tools/bin/sdkmanager --update \n\nRUN while read -r package; do PACKAGES=\"${PACKAGES}${package} \"; done \u003c /sdk/packages.txt \u0026\u0026 \\\n    ${ANDROID_HOME}/tools/bin/sdkmanager ${PACKAGES}\n```\n\nThe Dockerfile code contains the following,\n\n  - The base OS image is defined in **FROM**\n  - The maintainer of the docker in **MAINTAINER**\n  - The Android SDK tools is update after evey new release. With every new update the version number in the download link is updated. Having a variable **ENV VERSION_SDK_TOOLS** for the version number reduces the effort in long run for maintaining the Dockerfile.\n  - **ENV ANDROID_HOME** is used for storing sdk folder name.\n  - **ENV PATH** is used for storing the android sdk tools path.\n  - **DEBIAN_FRONTEND** is used for installing the packages in Docker.\n  - **RUN apt-get -qq update** and the consecutive commands are used to update the packages and install packages.\n  - **RUN rm -f /etc/ssl/certs/java/cacerts;** is used for java ceritifcate.\n  - **RUN curl -s https://dl.google.com/android/repository/sdk-tools-linux-${VERSION_SDK_TOOLS}.zip** for downloading the Android SDK tools\n  - **RUN mkdir -p $ANDROID_HOME/licenses/** is used for creating a directory to accept Android SDK license during installation of Android SDK Tools.\n  - **ADD packages.txt /sdk** this command adds the file  packages.txt ti the sdk folder.\n\n    - The packages.txt contains the additional packages such as Google play services to be installed.\n\n    - Create a new file in the repository and name it as\n\n            packages.txt\n\n        and add the following code,\n\n        ```Docker\n            add-ons;addon-google_apis-google-24\n            build-tools;26.0.2\n            extras;android;m2repository\n            extras;google;m2repository\n            extras;google;google_play_services\n            extras;m2repository;com;android;support;constraint; constraint-layout;1.0.2\n            extras;m2repository;com;android;support;constraint; constraint-layout-solver;1.0.2\n            platform-tools\n            platforms;android-26\n        ```\n  - **RUN mkdir -p /root/.android \u0026\u0026** is used to create a folder and the subsequent commands are used to update the Android SDK.\n\n  - **RUN while read -r package; do PACKAGES=\"${PACKAGES}${package}** is used to run the packages.txt file. Next, the packages are downloaded and installed.\n\n- After the creating the Dockerfile and adding the mentioned code above. Next, go to [Docker hub](https://hub.docker.com) and click on **create a automated build**\n\n![](./images/create-automate-build.png)\n\n- Select the linked Github or bitbucket account to access the Github or Bitbucket repository.\n\n![select the linked github account to access the github repository](./images/link-github-ro-bitbucket.png)\n\n- Select the Github or Bitbucket repository.\n\n![select the github repository file](./images/select-the-github-repository-in-docker.png)\n\n- Add a short description for the automated build and click on create.\n\n![creation of automated build in docker](./images/docker-automated-build-creation.png)\n\n- Build page will be shown after completing the creation of automated build.\n\n![build overview page](./images/donw-creating-automated-build.png)\n\n- Next, click on **Build Settings** tab and click on **trigger** to **trigger** a build job.\n\n![](./images/trigger-a-build-job.png)\n\n- When the build job is completed. Click on **Build Details** to see the status of the build. **Success** indicated the build is successfully built the docker image. Now, the Docker image is ready.\n\n![](./images/build-details.png)\n\n## GitLab\n\nFollow the instructions on GitLab Documentation about [Creatin .gitlab-ci.yml](https://docs.gitlab.com/ee/ci/quick_start/README.html) file.\n\nA standard template file for Android application development provided by GitLab as follows,\n\n```yml\n# This file is a template, and might need editing before it works on your project.\n# Read more about this script on this blog post https://about.gitlab.com/2016/11/30/setting-up-gitlab-ci-for-android-projects/, by Greyson Parrelli\nimage: openjdk:8-jdk\n\nvariables:\n  ANDROID_COMPILE_SDK: \"25\"\n  ANDROID_BUILD_TOOLS: \"24.0.0\"\n  ANDROID_SDK_TOOLS: \"24.4.1\"\n\nbefore_script:\n  - apt-get --quiet update --yes\n  - apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1\n  - wget --quiet --output-document=android-sdk.tgz https://dl.google.com/android/android-sdk_r${ANDROID_SDK_TOOLS}-linux.tgz\n  - tar --extract --gzip --file=android-sdk.tgz\n  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter android-${ANDROID_COMPILE_SDK}\n  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter platform-tools\n  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter build-tools-${ANDROID_BUILD_TOOLS}\n  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-android-m2repository\n  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-google-google_play_services\n  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-google-m2repository\n  - export ANDROID_HOME=$PWD/android-sdk-linux\n  - export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/\n  - chmod +x ./gradlew\n\nstages:\n  - build\n  - test\n\nbuild:\n  stage: build\n  script:\n    - ./gradlew assembleDebug\n  artifacts:\n    paths:\n    - app/build/outputs/\n\nunitTests:\n  stage: test\n  script:\n    - ./gradlew test\n\nfunctionalTests:\n  stage: test\n  script:\n    - 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\n    - chmod +x android-wait-for-emulator\n    - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter sys-img-x86-google_apis-${ANDROID_COMPILE_SDK}\n    - echo no | android-sdk-linux/tools/android create avd -n test -t android-${ANDROID_COMPILE_SDK} --abi google_apis/x86\n    - android-sdk-linux/tools/emulator64-x86 -avd test -no-window -no-audio \u0026\n    - ./android-wait-for-emulator\n    - adb shell input keyevent 82\n    - ./gradlew cAT\n\n```\n\n![GitLab CI yml android template selection](./images/Gitlab-CI-standard-template.png)\n\nIn the template, **openjdk:8-jdk** Docker image is used and all the Android SDK tools and packages are installed during the build job. They are listed in **before_script**.\n\nInstead of downloading and installing Android SDK tools and packages every time during the build job. We can use the Docker image built above in the **.gitLab-ci.yml file**.\n\nThe Docker image created above can be used as follows,\n\n        sakarsh/gitlab-ci-android-akarsh-seggemu:latest\n\nBy specifying the **Docker hub username/Docker image**. The **:latest** is used to get the latest build from Docker.\n\nUsing the Docker image mentioned above in **.gitlab-ci.yml** as follows,\n```yml\nimage: sakarsh/gitlab-ci-android-akarsh-seggemu:latest\n\nbefore_script:\n  - export GRADLE_USER_HOME=`pwd`/.gradle\n  - mkdir -p $GRADLE_USER_HOME\n  - chmod +x ./gradlew\n\nstages:\n  - build\n  - test\n\nbuild:\n  stage: build\n  script:\n    - ./gradlew assembleDebug\n  artifacts:\n    paths:\n    - app/build/outputs/\n\nunitTests:\n  stage: test\n  script:\n    - ./gradlew test\n\nfunctionalTests:\n  stage: test\n  script:\n    - 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\n    - chmod +x android-wait-for-emulator\n    - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter sys-img-x86-google_apis-${ANDROID_COMPILE_SDK}\n    - echo no | android-sdk-linux/tools/android create avd -n test -t android-${ANDROID_COMPILE_SDK} --abi google_apis/x86\n    - android-sdk-linux/tools/emulator64-x86 -avd test -no-window -no-audio \u0026\n    - ./android-wait-for-emulator\n    - adb shell input keyevent 82\n    - ./gradlew cAT\n\n```\n\nUsing an already configured Docker image with Android SDK tools and packages decreases the total build time.\n\n### Tutorials\n\n- [Dockerfile project](http://dockerfile.github.io/)\n\n- [GitLab CI](https://docs.gitlab.com/ee/ci/)\n\n### References to Dockerfiles\n\n- [dockerfiles](https://github.com/jessfraz/dockerfiles) - contains various Dockerfiles.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakarsh%2Fandroid-ci-tutorial-for-docker-and-gitlab","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakarsh%2Fandroid-ci-tutorial-for-docker-and-gitlab","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakarsh%2Fandroid-ci-tutorial-for-docker-and-gitlab/lists"}