How to Send APK File Automatically with Firebase App Distribution

Hardik Dungrani
Dec 24, 2019 · 4 min read

Now, I will share about how developers can send APKs to anyone who needs it directly.

You can integrate App Distribution into your Android build process using the App Distribution Gradle plugin. The plugin lets you specify your testers and release notes in your app’s build.gradle file, letting you configure distributions for different build types and variants of your app.

Before you begin

If you haven’t already, add Firebase to your Android project.

If you aren’t using any other Firebase products, you only have to create a project and register your app.

Download .json file from Firebase and add file to your project(module).

1. Set up your Android project

Open the build.gradle (project) file and embed the following plugin firebase appdistribution:

classpath ''
build.gradle (project)

Now, do not press the Sync button first. Open the build.gradle (module) file and embed the following script:

apply plugin: ''

It will be like this:

build.gradle (module)

Now Sync the project.

2. Authenticate with Firebase

Before you can use the Gradle plugin, you must first authenticate with your Firebase project. There are three ways to achieve this:

Authenticate using your Google Account

  • Run the following command:
For Window PC : </your_project/> gradlew appDistributionLogin
For Mac/Linux PC : </your_project/> ./gradlew appDistributionLogin
  • The command prints an authentication link.
  • Open the link in a browser.
  • When prompted, sign in to your Google Account and grant permission to access your Firebase project. The Gradle command prints a refresh token, which the App Distribution plugin uses to authenticate with Firebase.
  • Set the environment variable FIREBASE_TOKEN to the token from the previous step:
For Window PC : set FIREBASE_TOKEN=<token>
For Mac/Linux PC : export FIREBASE_TOKEN=<token>

Authenticate using a service account

To authenticate using service account credentials:

  • Add the Firebase Quality Admin role.
  • Create a private json key and move the key to a location accessible to your build environment. Be sure to keep this file somewhere safe, as it grants administrator access to your Firebase project.
  • Skip this step if you created your app after September 20, 2019: In the Google APIs console, enable the Firebase App Distribution API. When prompted, select the project with the same name as your Firebase project.
  • Provide or locate your service account credentials:

A. To pass Gradle your service account key, in your build.gradle file, set the property serviceCredentialsFile to the private key JSON file which you previously downloaded in above steps.

build.gradle (module)

B. set the environment variable GOOGLE_APPLICATION_CREDENTIALS. Replace [PATH] with the path of the private key JSON file and [FILE_NAME] with the filename.

For Window PC : set GOOGLE_APPLICATION_CREDENTIALS=/path/to/file.jsonFor Mac/Linux PC :  export GOOGLE_APPLICATION_CREDENTIALS=/path/to/file.json

3. Configure your distribution properties

In your app/build.gradle file, configure App Distribution by adding at least one firebaseAppDistribution section

buildTypes {
release {

firebaseAppDistribution {
serviceCredentialsFile = "/path/to/serviceaccount.json"
releaseNotesFile = "/path/to/releasenotes.txt"
testers = ",,"

4. Distribute your app to testers

Now it’s time we try to do (semi) automatic APK distribution. The first thing to do is to make the APK and the second thing just do the APK distribution.

For example, to distribute your app using the release build variant, run the following step:

For Window PC: gradlew assembleRelease appDistributionUploadReleaseFor Mac/Linux PC: gradlew assembleRelease appDistributionUploadRelease

Press the Enter key and wait until the process is complete and if successful, the output on the terminal will be like this:

You can check app successfully uploaded in App Distribution section in Firebase Console.

After that testers got mail of how to accept invitation and download APK.

Enjoy your testing!!!

So, that’s it, this tutorial is for send APK file automatically with Firebase app distribution in Android.

Hopefully the knowledge is useful.

Hardik Dungrani

Written by

I have extensive experience in developing innovative and complex Android /iOS Apps and also in Website Developing. Been working in Kotlin for the last 2 years.

More From Medium

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade