iTranslated by AI
Deploying Android apps to Firebase App Distribution with codemagic.yaml
Introduction
- This is a memo documenting the process of publishing an Android app to Firebase App Distribution using a Codemagic yaml file.
- General flow
- Prerequisites
- Build verification and trigger settings on Codemagic
- Publishing based on service account authentication
Reference Articles
Continuous Integration & Delivery (CI/CD) for Android | Codemagic Blog
I will proceed by referring to the article above.
Also, I am proceeding on the assumption that the target Android project has already been added to a Codemagic App.
Environment Setup and Preparation
1. Prerequisites
1-1. Setting up Testers and Groups in Firebase App Distribution

In this case, I will create a group called "Developer" under "Testers & Groups" so that notifications are sent when there is a new release.
*Note: If it's your first time, clicking "Get Started" should display the screen shown above.
1-2. buildTypes and productFlavors
I am assuming the following buildTypes and productFlavors configuration for this deployment.
// app/build.gradle.kts
android {
// ...
flavorDimensions += "default"
productFlavors {
create("dev") {
signingConfig = signingConfigs.getByName("dev") // signingConfig already specified
isDefault = true
applicationIdSuffix = ".dev"
dimension = "default"
}
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
}
CI Build
1. A Simple Workflow for Testing and Building
First, create a simple workflow. Create a codemagic.yaml file in the project root with the following content.
workflows:
build-dev-android-workflow:
name: Build Dev Android Workflow
max_build_duration: 60
instance_type: mac_mini_m1
environment:
groups:
- setup # If necessary for changing JAVA_HOME (see troubleshooting for details)
scripts:
- name: Run tests
script: ./gradlew test
- name: Build devRelease
script: ./gradlew assembleDevRelease
artifacts:
- app/build/outputs/apk/**/*.apk
Once you have committed it, push it immediately.
1-1. Manual Build
After pushing, check the Codemagic dashboard, and you should be able to "Start your first build" for the target project.

Configure the red-framed settings as needed and click "Start new build" to begin the build.

If the build is successful, you're good to go!
1-2. Enabling Builds on Push to a Specific Branch
Referring to the link above, add the following. In this case, the build will run when a push is made to the develop branch.
triggering:
events:
- push
branch_patterns:
- pattern: "develop"
include: true
source: true
Publishing to Firebase App Distribution
Authentication via Service Account
From the Firebase dashboard, click the gear icon > Service accounts > N service accounts.

Once the GCP screen opens, select "Service accounts" from the left menu and click "Create service account" from the top menu. Enter the service account details and click "Create and continue".

Next, for "Select a role", choose "Firebase App Distribution Admin SDK Service Agent".

Finally, click "Done" without entering anything else.

Next, click "Manage keys" from the menu of the created service account.

Go to "Add key" > "Create new key", select "JSON" as the key type, and click "Create". The downloaded JSON file will be used later, so manage it in an appropriate location.

Codemagic Environment Variable Settings
Copy the content of the JSON file you just downloaded to your clipboard.
cat xxxxxxxxx.json | pbcopy
In the "Environment variables" tab of the target app settings in Codemagic, add a new environment variable called FIREBASE_SERVICE_ACCOUNT.

Paste the content you copied to the clipboard into the value field.
Finally, add the following to codemagic.yaml and push it.
publishing:
firebase:
firebase_service_account: $FIREBASE_SERVICE_ACCOUNT
android:
app_id: $ANDROID_APP_ID
groups:
- Developer
If the app is released in Firebase App Distribution as follows, it's a success!

Troubleshooting
Error: Android Gradle plugin requires Java 17 to run. You are currently using Java 11. occurs!
Error details
* What went wrong:
An exception occurred applying plugin request [id: 'com.android.application', version: '8.1.1']
> Failed to apply plugin 'com.android.internal.application'.
> Android Gradle plugin requires Java 17 to run. You are currently using Java 11.
Your current JDK is located in /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home
You can try some of the following options:
- changing the IDE settings.
- changing the JAVA_HOME environment variable.
- changing `org.gradle.java.home` in `gradle.properties`.
Solution
The location of JAVA_HOME for Java 17 is listed here.

Referring to the above, select "Environment variables" from the target app's settings screen in Codemagic and add the following:
Name: JAVA_HOME
Value: /Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home
Variable group: setup (change the group setting as necessary)

The following error occurs during publishing
Authenticating with `--token` is deprecated and will be removed in a future major version of `firebase-tools`. Instead, use a service account key with `GOOGLE_APPLICATION_CREDENTIALS`:
Currently, firebase_token cannot be used, so you need to use firebase_service_account instead.
Discussion