# Android Application -> Firebase Distribution

### Create a service account:

* On the [Google Cloud Console](https://console.cloud.google.com/projectselector2/iam-admin/serviceaccounts), select your project and create a new service account.
  * Add the `Firebase App Distribution Admin` role.
* Create a private JSON key.
* [Enable the Firebase App Distribution API](https://console.developers.google.com/apis/api/firebaseappdistribution.googleapis.com/overview?project=). When prompted, select the project with the same name as your Firebase project.
* Encode the service account creds using base64

```bash
base64 service-account-credentials.json
```

* Then put this encoded value in code build env\_vars of the build project with the name `SERVICE_ACCOUNT_CREDENTIALS_ENCODED` and type `PARAMETER_STORE (secrets manager)`
* `To decode the credentials and write to file, run the below command in build.`

```bash
echo $SERVICE_ACCOUNT_CREDENTIALS_ENCODED | base64 -di >> <CODE_DIR>/app/service-account-credentials.json
```

**Changes in App Config:**

* Add the below dependency in `apps/crm-agent-mobile-app/android/build.gradle` > `buildscript` > `dependencies`

```bash
classpath('com.google.firebase:firebase-appdistribution-gradle:4.0.0')
```

* Add the below line at `app/build.gradle` (below `com.android.application` plugin)

```bash
apply plugin: 'com.google.firebase.appdistribution'
```

* Add the below snippet in `app/build.gradle` > `/android` > `buildTypes` > `release`

```bash
firebaseAppDistribution {
	appId="1:1234567890:android:321abc456def7890",
	artifactType="APK"
	releaseNotesFile=""
	serviceCredentialsFile="app/service-account-credentials.json"
	groupsFile=""
}
```

* Update `releaseNotesFile`, `groupsFile` paths.
* `groupsFile` file contains comma-separated testers' group names.
* For more details on other attributes here, go through [Distribute gradle](https://firebase.google.com/docs/app-distribution/android/distribute-gradle)

### How to Distribute?

Run the below command to build and distribute the app to firebase.

```bash
./gradlew assembleRelease appDistributionUploadRelease
```
