How to Send APK File Automatically with Firebase App Distribution
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:
Now, do not press the Sync button first. Open the build.gradle (module) file and embed the following script:
apply plugin: 'com.google.firebase.appdistribution'
It will be like this:
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_TOKENto 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:
- On the Google Cloud Platform console, select your project and create a new service account.
- 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.
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
app/build.gradle file, configure App Distribution by adding at least one
appId = "APP ID FROM FIREBASE"
serviceCredentialsFile = "/path/to/serviceaccount.json"
releaseNotesFile = "/path/to/releasenotes.txt"
testers = "email@example.com, firstname.lastname@example.org, email@example.com"
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:
- Open Terminal
- Run the following command to create an APK and Distribute to testers.
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.