Build & Release APK via GitHub Action

- 4 mins

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.

Process

Diagram

All this just by pushing one new tag to your GitHub!

Result

ApkRelease


How to achieve that?

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.

Prerequisite

Secrets

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 GITHUB_TOKEN provided universally will fail to authorize the user. This is the workaround and it works.

How to get Secret?

Environment Variables

You’ll need to provide these environment variables to specify exactly what information is needed to build the APK.

YML

name: Build & Publish Release APK

on:
  push:
    tags:
      - '*'

jobs:
  Gradle:
    runs-on: ubuntu-latest
    steps:
    - name: checkout code
      uses: actions/checkout@v2
    - name: setup jdk
      uses: actions/setup-java@v1
      with:
        java-version: 11
    - name: Make Gradle executable
      run: chmod +x ./gradlew
    - name: Build Release APK
      run: ./gradlew assembleRelease
    - name: Releasing using Hub
      uses: sangatdesai/release-apk@main
      env:
       GITHUB_TOKEN: $
       APP_FOLDER: app

Steps

How to push a new tag?

Git add .
Git commit -m "new release"
git push
git tag 1.0
git push origin 1.0

PushTag


Further Customization

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

YML

      ...
    - name: Build Debug APK
      run: ./gradlew assembleDebug
      ...

What Next?

GitHub Action Marketplace

I have Published this on GitHub Marketplace for anyone to use this and by default it will copy the release apk with any name from the ‘release’ folder of outputs.

But if for some reason you want make changes, do create a fork and edit the necessary files.

Credits

Based on ShaunLWM & kyze8439690

Sangat Desai

Sangat Desai

Humanizing Products!

rss facebook twitter github gitlab youtube mail spotify lastfm instagram linkedin google google-plus pinterest medium vimeo stackoverflow reddit quora quora