# Firebase App Distribution (Android)

When the team needs to quickly test a new Android build before publishing to the store, I use **Firebase App Distribution**. I also combine it with **GitHub Actions** to automatically build and release test builds after each code push.

My goals are:

* Fast internal testing.
* Standardize the APK build and distribution flow.
* Automate CI/CD to reduce manual work.

## Prepare testers in Firebase Console

### Step 1: Create a tester group

Go to: [Firebase Console](https://console.firebase.google.com/)

Open `App Distribution -> Get started -> Testers & Groups`:

* Create a group (for example: `wong-test`).
* Add tester emails to the group.

After a build is uploaded successfully, testers will receive an email invitation to install the app.

### Step 2: Make sure Firebase config files match the correct project

In your Flutter project, check and replace these files correctly:

```
android/app/google-services.json
ios/Runner/GoogleService-Info.plist
```

If you change the Firebase project, you need to replace both files accordingly.

## Install required tools on local machine

### Step 1: Add Flutter pub cache to PATH

```bash
echo 'export PATH="$PATH:$HOME/.pub-cache/bin"' >> ~/.zshrc && source ~/.zshrc
```

### Step 2: Install Firebase CLI

```bash
npm install -g firebase-tools
```

### Step 3: Login to Firebase and verify projects

```bash
firebase login
firebase projects:list
```

## Configure FlutterFire for Android and iOS

Run:

```bash
flutterfire configure \
  --project your-project-id \
  --platforms android,ios \
  --android-package-name com.example.app \
  --ios-bundle-id com.example.baseApp
```

Note: `your-project-id` is the Project ID in Firebase `Project settings -> General`.

## Update Gradle for Google Services plugin

In `android/build.gradle`, add:

```gradle
buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        // Required for Firebase Google Services plugin
        classpath "com.google.gms:google-services:4.4.2"
    }
}
```

If your project already has this block, just verify the plugin version.

## Create CI credentials from Google Cloud

Go to `Google Cloud Console -> IAM & Admin -> Service Accounts`:

1. Create a new service account, for example `ci-app-distribution`.
2. Assign role: `Firebase App Distribution Admin`.
3. Open that service account -> `Keys` -> `Add key` -> `Create new key` -> choose `JSON`.
4. Download the JSON key file and keep it secret (do not commit to git).

## Configure GitHub Secrets for CI/CD

Go to `GitHub -> Repository -> Settings -> Secrets and variables -> Actions` and add:

* `APP_ID`: Firebase App ID of your Android app (format `1:1234567890:android:abcxyz...`)
* `FIREBASE_TOKEN`: token from `firebase login:ci`

Get token:

```bash
firebase login:ci
```

Copy the returned token and paste it into the `FIREBASE_TOKEN` secret.

## Manually upload app to Firebase App Distribution

### Step 1: Build release APK

```bash
flutter build apk --release
```

### Step 2: Upload APK to Firebase

```bash
firebase appdistribution:distribute build/app/outputs/flutter-apk/app-release.apk \
  --app "1:1234567890:android:abcxyz123456" \
  --groups "wong-test" \
  --token "$FIREBASE_TOKEN"
```

If you want to shorten this long command, you can wrap it in a `Makefile` target and run one short command instead. See the Make guide here:

{% content-ref url="../easy-code/make" %}
[make](https://wong-coupon.gitbook.io/flutter/easy-code/make)
{% endcontent-ref %}

When upload succeeds, testers will receive an email and can install via **Firebase App Tester**.

## Set up CI/CD with GitHub Actions

Create file:

```
.github/workflows/firebase-distribute.yml
```

Example content:

```yaml
name: Android Firebase Distribution

on:
  push:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      # 1. Checkout repository
      - uses: actions/checkout@v4

      # 2. Setup Flutter SDK
      - name: Setup Flutter
        uses: subosito/flutter-action@v2
        with:
          flutter-version: '3.27.0'
          channel: 'stable'

      # 3. Get Flutter dependencies
      - name: Get dependencies
        run: flutter pub get

      # 4. Build release APK
      - name: Build Android APK (release)
        run: flutter build apk --release

      # 5. Install Firebase CLI
      - name: Install Firebase CLI
        run: npm install -g firebase-tools

      # 6. Upload to Firebase App Distribution
      - name: Distribute to Firebase App Distribution
        env:
          FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
          APP_ID: ${{ secrets.APP_ID }}
        run: |
          firebase appdistribution:distribute build/app/outputs/flutter-apk/app-release.apk \
            --app "$APP_ID" \
            --groups "wong-test" \
            --token "$FIREBASE_TOKEN"
```

On every code push, this workflow will automatically build and upload the APK to Firebase.

## Check CI/CD results

Go to:

* `GitHub -> Actions` to view pipeline logs.
* `Firebase Console -> App Distribution` to verify published builds.

## Important security notes

* Do not commit service account JSON key files to the repository.
* Do not hard-code tokens in source code or workflow files.
* Always use `GitHub Secrets` for `APP_ID`, `FIREBASE_TOKEN`, and other sensitive data.

## Conclusion

Firebase App Distribution helps me test new builds much faster before store release. When combined with GitHub Actions, the test release flow becomes almost fully automated. I will soon add an iOS section.

If you also want a full store release workflow, combine this with the Fastlane article:

{% content-ref url="fastlane-google-play" %}
[fastlane-google-play](https://wong-coupon.gitbook.io/flutter/easy-operation/fastlane-google-play)
{% endcontent-ref %}

[Buy Me a Coffee](https://buymeacoffee.com/ducmng12g) | [Support Me on Ko-fi](https://ko-fi.com/I2I81AEJG8)
