Automate Firebase App Distribution with GitHub Actions

·

3 min read

Firebase App Distribution is a popular service for managing app testing versions, offering unlimited usage. This guide provides a simple setup for using GitHub Actions to deliver app versions efficiently.

Introduction

Automating the distribution of your Android app can save time and reduce errors. By integrating Firebase App Distribution with GitHub Actions, you can streamline the process of delivering app versions to your testers. This guide will walk you through the setup process step-by-step.

Firebase

  1. Create a firebase project

  2. Goto Run > App Distribution

  3. Select Android and fill the non-optional fields and proceed

  4. Download the google-services.json at the end of the setup

  5. Select Testers and Groups tab

  6. Click Add group and create a tester group for app version should distribute

Google Cloud Platform

  1. Goto Google Cloud Platform and select the project you just created at firebase

  2. Goto Service Accounts

  3. Click CREATE SERVICE ACCOUNT

  4. Fill the service account name and id

  5. Select the role as Firebase App Distribution Admin and click done

  6. Find the service account your just created and select Manage Key

  7. Create a new Key

  8. Select a json key type then you will auto download the json key to local. It will be used when setting GitHub Action.

Android Project

  1. Place the google-services.json from firebase at project app/ folder

  2. Create a yml file .github/workflows/firebase-app-distribution-action.yml

  3. Setup the steps with following

     name: Build and Distribute APK
    
     # Currently is manually trigger, you may change it based on your usage
     on:
       workflow_dispatch:
    
     jobs:
       build:
         runs-on: ubuntu-latest
    
         steps:
         - name: Checkout code
           uses: actions/checkout@v4
    
         # Change the JDK fit your project
         - name: Set up JDK 17
           uses: actions/setup-java@v4
           with:
             distribution: 'zulu'
             java-version: '17'
    
         - name: Set up Android SDK
           uses: android-actions/setup-android@v3
    
         - name: Decrypt and set up Android keystore
           env:
             ANDROID_KEYSTORE: ${{ secrets.ANDROID_KEYSTORE }}
           run: |
             echo $ANDROID_KEYSTORE | base64 --decode > keystore.jks
    
         - name: Build Release apk
           env:
             KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
             KEYSTORE_ALIAS: ${{ secrets.KEYSTORE_ALIAS }}
             KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
           run: ./gradlew assembleRelease --stacktrace
    
         - name: Get release file apk path
           id: releaseApk
           run: echo "apkfile=$(find app/build/outputs/apk/release/*.apk)" >> $GITHUB_OUTPUT
    
         - name: Upload to Firebase App Distribution
           uses: wzieba/Firebase-Distribution-Github-Action@v1
           with:
             appId: ${{ secrets.FIREBASE_APP_ID }}
             serviceCredentialsFileContent: ${{ secrets.CREDENTIAL_FILE_CONTENT }}
             groups: testers
             file: ${{ steps.releaseApk.outputs.apkfile }}
    
  4. Goto project build.gradle and add plugins

     plugins {
         //...
         id 'com.google.gms.google-services' version '4.4.2' apply false
     }
    
  5. Goto app build.gradle and add plugins, dependencies and sign configs later on will ready for GitHub Action setup

     plugins {
         // ...
         id 'com.google.gms.google-services'
     }
     android {
         signingConfigs {
             release {
                 storeFile file("../keystore.jks")
                 storePassword System.getenv("KEYSTORE_PASSWORD")
                 keyAlias System.getenv("KEYSTORE_ALIAS")
                 keyPassword System.getenv("KEY_PASSWORD")
             }
         }
     }
     dependencies {
         //...
         implementation platform('com.google.firebase:firebase-bom:33.1.1')
         implementation 'com.google.firebase:firebase-analytics'
     }
    
  6. Sync and run the project once to ensure the dependencies and plugins version are match with your current project setup

  7. Push the commits to GitHub

GitHub

  1. Goto project repository's setting page

  2. Goto Secrets and Variables > Action

  3. Create following set of Repository secrets. We have defined them in our firebase-app-distribution-action.yml

    1. ANDROID_KEYSTORE

    2. CREDENTIAL_FILE_CONTENT

    3. FIREBASE_APP_ID

    4. KEYSTORE_ALIAS

    5. KEYSTORE_PASSWORD

    6. KEY_PASSWORD

  4. Goto Action > Build and Distribute APK workflow

  5. Click run workflow if you are manually trigger workflow

Result

Once the workflow runs successfully, the app version will be uploaded and a notification will be sent to the testers group.

By following these steps, you can automate the distribution of your Android app using Firebase App Distribution and GitHub Actions, making the process more efficient and reliable.