<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ahmad Bhatti on Medium]]></title>
        <description><![CDATA[Stories by Ahmad Bhatti on Medium]]></description>
        <link>https://medium.com/@Ahmad-Bhatti?source=rss-62b9bb318953------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*rXXPVa8Tnn6Ws60E61n_4A.png</url>
            <title>Stories by Ahmad Bhatti on Medium</title>
            <link>https://medium.com/@Ahmad-Bhatti?source=rss-62b9bb318953------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 06:44:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Ahmad-Bhatti/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Build CI/CD Pipeline for Android with GitLab]]></title>
            <link>https://medium.com/@Ahmad-Bhatti/build-ci-cd-pipeline-for-android-with-gitlab-ab4aa2aa4fe5?source=rss-62b9bb318953------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab4aa2aa4fe5</guid>
            <category><![CDATA[gitlab-runner]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Ahmad Bhatti]]></dc:creator>
            <pubDate>Thu, 09 Jun 2022 12:15:45 GMT</pubDate>
            <atom:updated>2022-06-09T12:59:27.514Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*arLLZfImFxctH7XmiLGl-g.jpeg" /></figure><blockquote>In this article I tried to create a pipeline for a sample project where you build and test your CI/CD using Gitlab.</blockquote><p>I hope you know all about what is CI/CD and its importance, so I simply go with building CI/CD with android,</p><p>In this article I have cover almost every step to build CI/CD pipeline</p><blockquote>Step 1: Setup Google play publisher plugin in you project</blockquote><blockquote>Step 2: Setup Signing configs</blockquote><blockquote>Step 3: Setup Google Play Console Authentication</blockquote><blockquote>Step 4: Setup Google play api with you project</blockquote><blockquote>Step 5: Setup and configuring .gitlab-ci.yml file</blockquote><blockquote>Step 6: Setup Shared Runner and Pipelines</blockquote><h3>Start with creating CI/CD with android</h3><h4>Step 1: Setup Google play publisher plugin in you project</h4><p>open your project <strong>build.gradle </strong>file and set the classpath dependency in buildscript.</p><blockquote><a href="https://github.com/Triple-T/gradle-play-publisher"><strong>Reference</strong></a><strong>:</strong> <a href="https://github.com/Triple-T/gradle-play-publisher">https://github.com/Triple-T/gradle-play-publisher</a></blockquote><pre>buildscript <strong>{<br>    </strong>dependencies <strong>{<br>        </strong>classpath &#39;com.github.triplet.gradle:play-publisher:1.1.5&#39;<br>    <strong>}<br>}</strong></pre><p>now open <strong>app/build.gradle</strong> file and add plugin.</p><pre>plugins <strong>{</strong><br>    id &#39;com.github.triplet.play&#39;<br><strong>}</strong></pre><h4>Step 2: Setup Signing configs</h4><p>now set signingConfigs in <strong>app/build.gradle</strong></p><pre>android <strong>{</strong><br>......<br>    defaultConfig <strong>{</strong></pre><pre>        .....<br>    <strong>}<br><br>    </strong>signingConfigs <strong>{<br>        </strong>release <strong>{<br>   </strong><br>            storeFile file(&quot;release-keystore.jks&quot;) //keystor<br>            storePassword &quot;password&quot;<br>            keyAlias &quot;alias&quot;<br>            keyPassword &quot;password&quot;<br>        <strong>}<br>    }</strong></pre><pre>...........</pre><pre>}</pre><p><strong>Note: </strong>keystore file in the same directory as the <strong>app/build.gradle</strong> file.</p><p>now add <strong>signingConfigs.release </strong>in buildType under release.</p><pre>buildTypes <strong>{<br>    </strong>release <strong>{</strong><br>        signingConfig signingConfigs.release<br>         ........</pre><pre>    <strong>}<br>}</strong></pre><p>Now your Android Studio Project is ready for “Gradle Play Publisher plugin” .Now we need to set <strong>Google Play Console Authentication.</strong></p><h4>Step 3: <strong>Setup</strong> <strong>Google Play Console Authentication</strong></h4><p>First we need to setup Google Service Account.</p><p>now open Google Play Console,<a href="https://play.google.com/console"> </a><a href="https://play.google.com/console">https://play.google.com/console</a> and create account (if you don’t have account).</p><p>then select the Setup tab &gt; API access</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*80dyDHVrGFlxE3Sx8o-8XQ.png" /></figure><p>click on <strong>Create new service account.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1015/1*Kfb9JdvhNmEKIa9Sw2QMpQ.png" /></figure><p>then a pop-up will appear.</p><p>now click on <strong>Google Cloud Platform</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*ZiqdGVPJs5Vv3XFYCkP1iQ.png" /></figure><p>This will open a new tab in your browser.</p><p>then click on <strong>CREATE SETVICE ACCOUNT</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZJ1NposMdIaVTpVnYx95eg.png" /></figure><p>then in next screen in service account details section setup service account name and description(optional),</p><p>then in Grant this service account access to project section select <strong>Role: Owner </strong>then click continue, then next step is optional .</p><p>now click on <strong>Done.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*JsZqScxLjrqri-Yg8l_8LQ.png" /></figure><p>now after this we back to previous page and we see there is new service account is created.</p><p>now click on menu of new service account then click on <strong>Manage keys</strong> option</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yCcdFuKwXvZe2OCzw3zOgg.png" /></figure><p>then in next screen click on <strong>ADD KEY </strong>dropdown then click <strong>Create new key.</strong></p><figure><img alt="Click on create new Key" src="https://cdn-images-1.medium.com/max/582/1*NCA4rH8RN3Bx0GUoDraWBQ.png" /><figcaption>Click on Create new key</figcaption></figure><p>after that a popup will appear, select key type&gt; <strong>JSON</strong> than click on <strong>CREATE</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*Vzpp48gbMXR2DN3QoaBf3g.png" /></figure><p>After that you see a <strong>json </strong>file of your key will be download in your pc, then save this json file for future use.</p><p>then back to your <strong>Google Play Console</strong> where you left popup screen,</p><p>Click on <strong>Done </strong>for creating new service account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/657/1*RyEJ6-iwKnMeBQkAxm1k2w.png" /></figure><p>After that you will see there is new service account will be create in <strong>Service account</strong> secretion.</p><p>then click on<strong> Grant permissions </strong>and give the permission to user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*37VjevFBIeB7kE2vS46j9Q.png" /></figure><p>After that the new screen will appear where you can see user details and permissions.</p><p>you can check <strong>Set access expiry date</strong> if you want (optional).</p><p>in<strong> Account permissions</strong> section check <strong>Admin(all permission)</strong>(optional).</p><p>then at the end click on <strong>Invite user.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*VXiGfzhbQ0CFzmyli6nYBw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/983/1*11I1aoCYeG8a8MX7FYeC4g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/269/1*sicJX-4PN90z3UQcQkqtbg.png" /></figure><p>then click on <strong>Sent Invitation</strong> button in pop up,</p><p>Now you can see you service account is appear in <strong>users </strong>section,</p><h4>Step 4: Setup Google play api with you project</h4><p>New if you remember that we save our key <strong>json file</strong> in some kind of place,</p><p>now copy this <strong>json file </strong>and paste it in your <strong>project&gt;app</strong> directory.</p><p>After that go to your Android Studio then open <strong>app/build.gradle</strong> file and add this code,</p><pre>android {<br>.....<br>}</pre><pre>play <strong>{<br>    </strong>serviceAccountCredentials = file(&#39;pc-api-5901144735381435704-900-e2a645b4efce.json&#39;) // Json file in you app directory<br>    track = &#39;alpha&#39; // set track for playstore  like &#39;production&#39;,&#39;beta&#39;,&#39;alpha&#39;<br><strong>}<br><br></strong>dependencies <strong>{<br>.....<br>}</strong></pre><p>after that click on <strong>Sync Now </strong>and sync the project .</p><h4>Step 5: Setup and configuring .gitlab-ci.yml file</h4><blockquote><a href="https://docs.gitlab.com/ee/ci/yaml/"><strong>Reference</strong></a><strong>: </strong><a href="https://docs.gitlab.com/ee/ci/yaml/">https://docs.gitlab.com/ee/ci/yaml/</a></blockquote><p>First we have to create <strong><em>.gitlab-ci.yml </em></strong>inside you project directory,</p><p><strong><em>.gitlab-ci.yml</em></strong> is the basic config file to ensure your Android app compiles and passes unit and functional tests.</p><p>you can find <strong><em>.gitlab-ci.yml</em></strong> latest template from here.</p><blockquote><a href="https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Android.latest.gitlab-ci.yml">https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Android.latest.gitlab-ci.yml</a></blockquote><p>here is my <strong><em>.gitlab-ci.yml</em></strong></p><pre>image: openjdk:11-jdk<br><br>variables:<br><br>  # ANDROID_COMPILE_SDK is the version of Android you&#39;re compiling with.<br>  # It should match compileSdkVersion.<br>  ANDROID_COMPILE_SDK: &quot;32&quot;<br><br>  # ANDROID_BUILD_TOOLS is the version of the Android build tools you are using.<br>  # It should match buildToolsVersion.<br>  ANDROID_BUILD_TOOLS: &quot;32.1.0-rc1&quot;<br><br>  # It&#39;s what version of the command line tools we&#39;re going to download from the official site.<br>  # Official Site-&gt; https://developer.android.com/studio/index.html<br>  # There, look down below at the cli tools only, sdk tools package is of format:<br>  #        commandlinetools-os_type-ANDROID_SDK_TOOLS_latest.zip<br>  # when the script was last modified for latest compileSdkVersion, it was which is written down below<br>  ANDROID_SDK_TOOLS: &quot;7583922&quot;<br><br># Packages installation before running script<br>before_script:<br>  - apt-get --quiet update --yes<br>  - apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1<br><br>  # Setup path as ANDROID_SDK_ROOT for moving/exporting the downloaded sdk into it<br>  - export ANDROID_SDK_ROOT=&quot;${PWD}/android-home&quot;<br>  # Create a new directory at specified location<br>  - install -d $ANDROID_SDK_ROOT<br>  # Here we are installing androidSDK tools from official source,<br>  # (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)<br>  # after that unzipping those tools and<br>  # then running a series of SDK manager commands to install necessary android SDK packages that&#39;ll allow the app to build<br>  - wget --output-document=$ANDROID_SDK_ROOT/cmdline-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}_latest.zip<br>  # move to the archive at ANDROID_SDK_ROOT<br>  - pushd $ANDROID_SDK_ROOT<br>  - unzip -d cmdline-tools cmdline-tools.zip<br>  - pushd cmdline-tools<br>  # since commandline tools version 7583922 the root folder is named &quot;cmdline-tools&quot; so we rename it if necessary<br>  - mv cmdline-tools tools || true<br>  - popd<br>  - popd<br>  - export PATH=$PATH:${ANDROID_SDK_ROOT}/cmdline-tools/tools/bin/<br><br>  # Nothing fancy here, just checking sdkManager version<br>  - sdkmanager --version<br><br>  # use yes to accept all licenses<br>  - yes | sdkmanager --licenses || true<br>  - sdkmanager &quot;platforms;android-${ANDROID_COMPILE_SDK}&quot;<br>  - sdkmanager &quot;platform-tools&quot;<br>  - sdkmanager &quot;build-tools;${ANDROID_BUILD_TOOLS}&quot;<br><br>  # Not necessary, but just for surity<br>  - chmod +x ./gradlew<br><br>stages:<br>  - build<br>  - test<br><br>build:<br>  stage: build<br>  script:<br>    - ./gradlew assembleDebug <em># command to build and debug<br>  </em>only:<br>    - main <em>#set trigger for CICD if push or merge in master branch<br>  </em>artifacts:<br>    paths:<br>      - ./app/build/outputs/ <em># set artifact path which store your APK file<br><br></em>unitTests:<br>  stage: test<br>  script:<br>    - ./gradlew test</pre><p>you can use this file for testing (optional).</p><p>To understand the important part of this <strong><em>.gitbal-ci.yml</em></strong> file that dynamically creates files from the CI/CD Variable, you must read <a href="https://about.gitlab.com/blog/2018/10/24/setting-up-gitlab-ci-for-android-projects/">reference</a> mention below.</p><blockquote><a href="https://about.gitlab.com/blog/2018/10/24/setting-up-gitlab-ci-for-android-projects/"><strong>Reference</strong></a>: <a href="https://about.gitlab.com/blog/2018/10/24/setting-up-gitlab-ci-for-android-projects/">https://about.gitlab.com/blog/2018/10/24/setting-up-gitlab-ci-for-android-projects/</a></blockquote><p><em>As you see I have define two stages in my </em><em>.gitbal-ci.yml build and test stage,</em></p><p><em>For in our build stage we simply build and debug our app, after build stage is passed then our test stage is going to be running and then after passing test stage we can simply check out apk.</em></p><p><em>Lets implement this,</em></p><h4>Step 6: Setup Shared Runner and Pipelines</h4><p>First configure project to GitLab repository and then <strong>commit </strong>changes into your <strong>master </strong>branch(mention in yml file) that you made in your project and <strong>push </strong>into <strong>master </strong>branch in GitLab repository.</p><p>After project is successfully pushed to GitLab than go to <a href="https://gitlab.com/">Gitlab</a> and click on <strong>project&gt;CI/CD&gt;Pipelines</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*jeMFIgWAlXd4MPQPRhlsNg.png" /></figure><p>in next screen if you see this type of issue you need to <strong>Validate your account</strong> or <strong>create your own runner</strong> and use with this project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z2QdpNkiNn9bQuJids9zaA.png" /></figure><p>I personally go with <strong>validate my account</strong> because its simple, after validation you just need to unable your shared runner,</p><p>simply go to Gitlab <strong>Project&gt;Settings&gt;CI/CD&gt;Runners </strong>then <strong>Expand </strong>and enable shared runner,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*6j8rxYdBffMYjcYqSkSc3A.png" /></figure><p>otherwise you can create your own runner its simple I mention the link blow</p><p><a href="https://docs.gitlab.com/runner/install/">Install GitLab Runner | GitLab</a></p><p>If you not see this issue then you will see your pipeline is <strong>running</strong>,</p><p>if you remember we have define two stages in <em>.gitbal-ci.yml </em><strong>build </strong>and <strong>test</strong></p><p>this is your <strong>build </strong>stage is running</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EfXNzDY8PXTYgtSneA8pMw.png" /></figure><p>after completion of <strong>build </strong>stage then <strong>test </strong>stage is going to be running</p><p>now <strong>test </strong>stage is running</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*um3-prOFfl8XDUGVi6T_Rg.png" /></figure><p>now after completion and pass both <strong>build </strong>and <strong>test </strong>stages and branch can be Merged then you are finally ready and this is your success.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*w_9ttRVbVr0rUgaf" /><figcaption>Photo by <a href="https://unsplash.com/@krakenimages?utm_source=medium&amp;utm_medium=referral">krakenimages</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Here we can download the apk file from the Artifacts.</p><p>click on <strong>menu&gt;build:archive</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0jh3vHLUCLxpXPhep-OTmQ.png" /></figure><p>Now finally CI/CD is complete.👏</p><p>Thank you for reading this article. I hope you like this and I am sure its helps you to understand and implementation of <strong>CI/CD(Continuous Integration and Delivery)</strong> in which I tried to create a pipeline for a sample project where you build and test your CI/CD using Gitlab.</p><p>This is one of the most important skills for any software engineer in general and for android developers and also plays very important role in software development because it helps us to automate our builds and delivery process and minimize the time consumed in tedious tasks and errors.</p><blockquote><a href="https://github.com/ahmedijazbhatti111/CICDGitlabPracticeApp">Project link</a>:<a href="https://github.com/ahmedijazbhatti111/CICDGitlabPracticeApp"> https://github.com/ahmedijazbhatti111/CICDGitlabPracticeApp</a></blockquote><h4>If you enjoy this article, please Clap this and share to others!</h4><h3>Please leave a comment below if you facing any problem.</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab4aa2aa4fe5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>