# Deploying Android apps to Bitrise and Google Play

This guide describes how you can add your Android project to [bitrise.io](https://www.bitrise.io) and deploy the APK or AAB built from your project to [Google Play Store](https://play.google.com/store).

You need a new service account created in the Google Play Console so that Bitrise can authenticate with [Google Play Deploy](https://github.com/bitrise-io/steps-google-play-deploy) during your build. The new service account has to be invited to Google Play Console as a user with the appropriate permission.

To set up your project for the first time:

1. Register a [Google Play Developer Account](https://developer.android.com/distribute/console/). If you already have a Google Play Developer account, and have already deployed your app to Google Play Store, skip to [Setting up Google Play API access](#setting-up-google-play-api-access).
1. Go through [Setting up Google Play deployment for the first time](#setting-up-google-play-deployment-for-the-first-time).

## Setting up Google Play API access

Grant the Google Play API access to your project by creating a service account and granting the necessary user permissions to the service account.

1. Turn on the Google Play Developer API for your project: [Enable the API](https://developers.google.com/android-publisher/getting_started#enable).
1. Create a service account on Google Cloud Platform: [Create service accounts](https://developers.google.com/android-publisher/getting_started#service-account).
1. Create a new JSON key for the service account: [Create and delete service account keys](https://cloud.google.com/iam/docs/keys-create-delete).

   :::note[Instant download]

   When you click **Create** at the end of the process, the service account JSON key is automatically downloaded. Make sure to save it as you cannot access or download it again!

   :::
1. Invite your service account user on the **Users & Permissions** page in Google Play Console and grant the necessary permissions to be able to access and release apps on Google Play: [Use a service account](https://developers.google.com/android-publisher/getting_started#service-account).

Check out the [Google Play Developer API](https://developers.google.com/android-publisher/getting_started) guide if you need more information on the process.

You have successfully prepared your Google Play Console project. A services credential account has been created which is authorized to manage your releases.

## Setting up Google Play deployment for the first time

Deploying to Google play publishes your app to Google's online store. When you do it for the first time, this requires a bit more work than simply deploying to [bitrise.io](https://www.bitrise.io/). Once the necessary configurations are in place, it becomes very simple.

When configuring Google Play deployment for the first time, you need to link your Google Play Developer account to an API project, set up API access, and upload the service account JSON key to Bitrise.

1. Upload the first AAB or APK manually to Google Play [using the Google Play Console](https://support.google.com/googleplay/android-developer/answer/113469?hl=en).
1. [Link](https://developers.google.com/android-publisher/getting_started) your Google Play Developer Console to an API project.
1. [Set up API Access Clients using a service account](https://developers.google.com/android-publisher/getting_started): Please note when you create your service account on the Google Developer Console, you have to choose `json` as **Key Type**.
1. Grant the necessary rights to the service account with your [Google Play Console](https://play.google.com/apps/publish). Go to **Settings**, then **Users & permissions**, then **Invite new user**. Due to the way the Google Play Publisher API works, you have to grant at least the following permissions to the service account:

   - Access level: View app information.
   - Release management: Manage production releases, manage testing track releases.
   - Store presence: Edit store listing, pricing & distribution.
1. As an optional step, you can add translations to your Store Listing: [Translate & localize your app](https://support.google.com/googleplay/android-developer/answer/3125566?hl=en).
1. [Connect your Google service account to Bitrise](/bitrise-platform/integrations/connecting-a-google-service-account-to-bitrise).

## Deploying an Android app to bitrise.io

In this section, we'll go through how to deploy your Android project to [bitrise.io](https://www.bitrise.io/).

Deploying to [bitrise.io](https://www.bitrise.io) means that the build artifacts generated during the build will be available for download once the build is finished. You can use this to test your Android app on your own test devices, for example.

To deploy your app to [bitrise.io](https://www.bitrise.io/):

**Workflow Editor**

1. Make sure your Workflow contains the **[Android Build](https://www.bitrise.io/integrations/steps/android-build)** Step to build your app.

   Optionally, you can build your app with the **[Gradle Runner](https://www.bitrise.io/integrations/steps/gradle-runner)** Step. This requires a bit more configuration from you but allows for more extensive customization.
1. Add the **[Deploy to Bitrise.io](https://www.bitrise.io/integrations/steps/deploy-to-bitrise-io)** Step to your Workflow.

   :::tip[Notifying other users]

   You can use the **Notify: User Roles** and the **Notify: Emails** inputs of the Step to set up notifications about your deploy. Click the input names to reveal more information about how to configure them.

   :::
1. Optionally, set the **Enable public page for the App?** input of the Step to **true** so the Step [enables the public install page](/bitrise-ci/deploying/bitrise-ota-app-deployment#deploying-with-the-deploy-to-bitriseio-step) for your app.
1. Run a build.

**Configuration YAML**

1. Open the `bitrise.yml` file of your app.
1. Make sure your Workflow contains the `android-build` Step to build your app.

   ```yaml
   workflows:
     example-workflow:
       steps:
       - android-build@1:
   ```

   Optionally, you can build your app with the `gradle-runner` Step. This requires a bit more configuration from you but allows for more extensive customization.
1. Set the `module` and/or `variant` input to tell the Step what to build.

   In this example, we're building a debug variant of the Android project.

   ```yaml
   workflows:
     example-workflow:
       steps:
       - android-build@1:
           inputs:
           - variant: debug
       - deploy-to-bitrise-io: {}
   ```
1. Add the `deploy-to-bitrise-io` Step to your Workflow.

   ```yaml
   workflows:
     example-workflow:
       steps:
       - android-build@1:
           inputs:
           - variant: debug
       - deploy-to-bitrise-io: {}
   ```

   :::tip[Notifying other users]

   You can use the `notify_user_groups` and the `notify_email_list` inputs of the Step to set up notifications about your deploy:

   - The `notify_user_groups` input allows you to send notifications based on the [access roles](/bitrise-platform/projects/roles-and-permissions-for-bitrise-ci) granted to users. For example, you can set the input to notify everyone with an **Admin** and a **Developer** role. Set multiple roles separated by a comma: `- notify_user_groups: admins, testers`.
   - The `notify_email_list` input only accepts Secrets, and the Secret should contain comma-separated lists of email addresses.

   :::
1. Optionally, set the **Enable public page for the App?** input of the Step to **true** so the Step [enables the public install page](/bitrise-ci/deploying/bitrise-ota-app-deployment#deploying-with-the-deploy-to-bitriseio-step) for your app.
1. Run a build.

The **Deploy to Bitrise.io** Step will deploy the app. You can share the generated binary with your team members using the build’s URL.

**A bitrise.yml for deploying an Android app to Bitrise**

In this example, we're building the `debug` variant of an Android app, and deploy it to bitrise.io, as.

## Deploying to Google Play

Deploying to Google Play requires [a signed APK or AAB file](/bitrise-ci/code-signing/android-code-signing/android-code-signing-using-the-android-sign-step) and the **[Google Play Deploy](https://www.bitrise.io/integrations/steps/google-play-deploy)** Step.

**Workflow Editor**

1. [Upload your service account JSON key to the **Files** section](/bitrise-ci/run-and-analyze-builds/managing-build-files/uploading-files-for-your-builds).
1. In the **Files** section, copy the **Download URL** of your service account file.

   For example, `BITRISEIO_SERVICE_ACCOUNT_JSON_KEY_URL`.
1. Open the Workflow Editor and select **Secrets**.
1. Create a Secret with the copied download URL as the value.

   If you uploaded the JSON key file to Bitrise, the download URL is an Environment Variable so check the **Replace variables in inputs** checkbox.

   :::note[Direct link]

   If you use a direct link to your keystore file without uploading it to Bitrise, you don't need to check the **Replace the variables in inputs** option.

   :::
1. Add the **Google Play Deploy** Step to your Workflow.
1. In the **Service Account JSON key file path** input, paste the Secret you created.
1. In the **Package name** input, add the package name of your app.
1. In the **Track** input, add the track where you want to deploy your APK (for example, alpha/beta/rollout/production or any custom track you set).

**Configuration YAML**

1. [Upload your service account JSON key to the **Files** section](/bitrise-ci/run-and-analyze-builds/managing-build-files/uploading-files-for-your-builds).

   :::note[Uploading the service account JSON key file]

   We recommend uploading the service account JSON key to Bitrise but it is not mandatory: you can store it elsewhere and provide a direct link to it.

   :::
1. Open your app's Configuration YAML file and add the `google-play-deploy` Step to it.

   ```yaml
   deploy-workflow:
     steps: 
     - google-play-deploy: 
         inputs:
   ```
1. In the `service_account_json_key_path` input, you need to provide the path to the service account JSON key file.

   [Create a Secret](/bitrise-ci/configure-builds/secrets) to the path and reference that here.

   ```yaml
   deploy-workflow:
     steps: 
     - google-play-deploy: 
         inputs:   
         - service_account_json_key_path: "$BITRISEIO_SERVICE_ACCOUNT_JSON_KEY_URL"
   ```
1. In the `package` input, add [the package name](https://support.google.com/admob/answer/9972781?hl=en#:~:text=The%20package%20name%20of%20an,supported%20third%2Dparty%20Android%20stores.) of your app.

   ```yaml
   deploy-workflow:
     steps: 
     - google-play-deploy: 
         inputs:   
         - service_account_json_key_path: "$BITRISEIO_SERVICE_ACCOUNT_JSON_KEY_URL"
         - package_name: myApp
   ```
1. In the `track` input, add the track where you want to deploy your app binary (for example, alpha/beta/rollout/production or any custom track you set).

   ```yaml
   deploy-workflow:
     steps: 
     - google-play-deploy: 
         inputs:   
         - service_account_json_key_path: "$BITRISEIO_SERVICE_ACCOUNT_JSON_KEY_URL"
         - package_name: myApp
         - track: alpha
   ```

That’s all! Start or schedule a build and share the URL with external testers or distribute your app on an app store of your choice!
