<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.0">Jekyll</generator><link href="https://sangatdesai.com/feed.xml" rel="self" type="application/atom+xml" /><link href="https://sangatdesai.com/" rel="alternate" type="text/html" /><updated>2024-04-03T05:07:19+00:00</updated><id>https://sangatdesai.com/feed.xml</id><title type="html">Sangat Desai</title><subtitle>Product Manager • 10+ years of experience in building, launching &amp; scaling digital products for Fortune Global 500 Companies</subtitle><entry><title type="html">Build &amp;amp; Release APK via GitHub Action</title><link href="https://sangatdesai.com/build-release-apk-via-github-action/" rel="alternate" type="text/html" title="Build &amp;amp; Release APK via GitHub Action" /><published>2022-09-18T19:24:00+00:00</published><updated>2022-09-18T19:24:00+00:00</updated><id>https://sangatdesai.com/build-release-apk-via-github-action</id><content type="html" xml:base="https://sangatdesai.com/build-release-apk-via-github-action/">&lt;p&gt;Recently, I was wondering: is it possible to push a new android apk release via &lt;a href=&quot;https://firebase.google.com/docs/app-distribution&quot;&gt;Firebase App Distribution&lt;/a&gt; using &lt;a href=&quot;https://github.com/features/actions&quot;&gt;GitHub Action&lt;/a&gt; as CI/CD on every new tag release? Well, turns out you can and it is more simple than you can imagine! There are GitHub Actions written for this already, but if you go ahead and try it in default state, it fails and the lack of documented explanation makes it difficult for a new user to understand why. This is what led me to document this process step by step, so it can easily be understood, and edited as per the requirement.&lt;/p&gt;

&lt;h3 id=&quot;process&quot;&gt;Process&lt;/h3&gt;

&lt;p&gt;&lt;img src=&quot;https://res.cloudinary.com/sangat/image/upload/v1663525770/posts/Post_1/Diagram_1.png&quot; alt=&quot;Diagram&quot; /&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;All this just by pushing one new tag to your GitHub!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;result&quot;&gt;Result&lt;/h3&gt;

&lt;p&gt;&lt;img src=&quot;https://res.cloudinary.com/sangat/image/upload/v1663358454/posts/Post_1/ApkRelease.png&quot; alt=&quot;ApkRelease&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;how-to-achieve-that&quot;&gt;How to achieve that?&lt;/h2&gt;

&lt;p&gt;Follow the below process step by step to build and release APK via Github Actions when you push a new tag to your repository and it will automatically be attached to the release under this tag in your repo.&lt;/p&gt;

&lt;h3 id=&quot;prerequisite&quot;&gt;Prerequisite&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Create a GitHub repository and push your current Android Project to the GitHub repository&lt;/li&gt;
  &lt;li&gt;In your repository settings add the necessary secrets and environments variables as mentioned below.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;secrets&quot;&gt;Secrets&lt;/h4&gt;

&lt;p&gt;You’ll need to provide this secret token for this action to publish the APK to your own repo and to attach it with the release of the created tag (more about this below). I am not sure as to why using the default &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GITHUB_TOKEN&lt;/code&gt; provided universally will fail to authorize the user.
This is the workaround and it works.&lt;/p&gt;

&lt;h4 id=&quot;how-to-get-secret&quot;&gt;How to get Secret?&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;TOKEN&lt;/strong&gt;: Create a new &lt;a href=&quot;https://github.com/settings/tokens&quot;&gt;access token&lt;/a&gt; with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;repo&lt;/code&gt; access&lt;/li&gt;
  &lt;li&gt;Enter these secrets in the android project’s GitHub repository’s Settings &amp;gt; Secrets&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;environment-variables&quot;&gt;Environment Variables&lt;/h4&gt;

&lt;p&gt;You’ll need to provide these environment variables to specify exactly what information is needed to build the APK.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;APP_FOLDER&lt;/strong&gt;: main folder to search for the apk. Default is the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;app&lt;/code&gt; and you don’t need to change anything as of now.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;yml&quot;&gt;YML&lt;/h4&gt;

&lt;div class=&quot;language-yml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Build &amp;amp; Publish Release APK&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;tags&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;*'&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;jobs&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;Gradle&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;runs-on&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;checkout code&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;uses&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;actions/checkout@v2&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;setup jdk&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;uses&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;actions/setup-java@v1&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;with&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;java-version&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;11&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Make Gradle executable&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;chmod +x ./gradlew&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Build Release APK&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;./gradlew assembleRelease&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Releasing using Hub&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;uses&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;sangatdesai/release-apk@main&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;env&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
       &lt;span class=&quot;na&quot;&gt;GITHUB_TOKEN&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;$&lt;/span&gt;
       &lt;span class=&quot;na&quot;&gt;APP_FOLDER&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;app&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;steps&quot;&gt;Steps&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Provide the required Secrets and Environment variables in your GitHub Repo&lt;/li&gt;
  &lt;li&gt;To use this action simply create the below YML file at this specified path in your Android Project Directory’s Root Folder.
For e.g.: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.github/workflows/android.yml&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Copy &amp;amp; paste the above yaml code in your YML file&lt;/li&gt;
  &lt;li&gt;After that, whenever you are ready, make a commit and push it to Github Repo&lt;/li&gt;
  &lt;li&gt;Create and push the tag (for e.g. 1.0) against which the apk will be attached&lt;/li&gt;
  &lt;li&gt;As soon as you push the tag this github action will be initiated and generated apk will be released under releases with the same tag, which you can check in your github &amp;gt; code &amp;gt; releases (e.g v1.0)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;how-to-push-a-new-tag&quot;&gt;How to push a new tag?&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&quot;language-git&quot;&gt;Git add .
Git commit -m &quot;new release&quot;
git push
git tag 1.0
git push origin 1.0
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;img src=&quot;https://res.cloudinary.com/sangat/image/upload/v1663525575/posts/Post_1/PushTag.png&quot; alt=&quot;PushTag&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;further-customization&quot;&gt;Further Customization&lt;/h2&gt;

&lt;p&gt;By default this action will create the ‘release’ flavor and If you want to change the flavor of the apk being built to let’s say ‘debug’ then change the below line in your yml file&lt;/p&gt;

&lt;h4 id=&quot;yml-1&quot;&gt;YML&lt;/h4&gt;

&lt;div class=&quot;language-yml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;      &lt;span class=&quot;s&quot;&gt;...&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;- name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Build Debug APK&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;./gradlew assembleDebug&lt;/span&gt;
      &lt;span class=&quot;s&quot;&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;what-next&quot;&gt;What Next?&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;The generated apk at this stage is unsigned won’t be able to get installed. To do that we need to sign this for which we need to add few more lines to the current yml which we’ll see in the next part along with how the generated apk can be directly passed to the firebase’s app distribution list so your testers will have this automatically available.&lt;/li&gt;
  &lt;li&gt;While this will initiate GitHub action on a push of each new tag in your master branch, you can easily make changes in the yml to accomplish this on a different branch or initiate on a pull request.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;github-action-marketplace&quot;&gt;GitHub Action Marketplace&lt;/h2&gt;

&lt;p&gt;I have &lt;a href=&quot;https://github.com/marketplace/actions/build-and-release-apk&quot;&gt;Published this on GitHub Marketplace&lt;/a&gt; for anyone to use this and by default it will copy the release apk with any name from the ‘release’ folder of outputs.&lt;/p&gt;

&lt;p&gt;But if for some reason you want make changes, do create a fork and edit the necessary files.&lt;/p&gt;

&lt;h3 id=&quot;credits&quot;&gt;Credits&lt;/h3&gt;

&lt;p&gt;Based on &lt;a href=&quot;https://github.com/ShaunLWM/action-release-debugapk&quot;&gt;ShaunLWM&lt;/a&gt; &amp;amp; &lt;a href=&quot;https://github.com/kyze8439690/action-release-releaseapk&quot;&gt;kyze8439690&lt;/a&gt;&lt;/p&gt;</content><author><name>sangat</name></author><category term="blog" /><category term="Android" /><category term="Firebase" /><category term="Github" /><summary type="html">Recently, I was wondering: is it possible to push a new android apk release via Firebase App Distribution using GitHub Action as CI/CD on every new tag release? Well, turns out you can and it is more simple than you can imagine! There are GitHub Actions written for this already, but if you go ahead and try it in default state, it fails and the lack of documented explanation makes it difficult for a new user to understand why. This is what led me to document this process step by step, so it can easily be understood, and edited as per the requirement.</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://sangatdesai.com/" /><media:content medium="image" url="https://sangatdesai.com/" xmlns:media="http://search.yahoo.com/mrss/" /></entry></feed>