Deploying Android apps to Bitrise and Google Play

This guide describes how you can add your Android project to bitrise.io and deploy the APK or AAB built from your project to Google Play Store.

You need a new service account created in the Google Play Console so that Bitrise can authenticate with 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. 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.

  2. Go through 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 either creating a new API project or linking an existing API project. In this tutorial, we’re creating a new one.

  1. Go to your Google Play Console and click Settings. Click API access on the left menu bar. On the Linked Google Cloud project page, select Create new project option.

    apiaccessstart.jpg
  2. On the API access page, scroll down to Service accounts and click Create a new service account. Follow the instructions to get to Google Cloud Platform.

    createnewserviceaccount.jpg
  3. On the Google Cloud Platform, click + CREATE SERVICE ACCOUNT on the top menu bar.

    pluscreateserviceaccount.jpg
  4. A 3-step Create service account page comes up, where you have to provide a Service account name first. A Service account ID is automatically generated based on the Service account name you typed.

    serviceaccountdetails.jpg
  5. At the Grant this service account access to project step, select Browser in the Role dropdown. Although the second and third steps of the process are marked optional on Google Cloud Platform, those are essential for Bitrise to be able to use the service account access.

    serviceaccountdetails.png
  6. Fill out the Service account user role and Service account admins role fields of the Grant users access to this service account step. Hit DONE.

    grantuseraccess.jpg
  7. You land back on the API Access page of the Google Play Console where you can create a key to your new service account. Bitrise will use the key to authenticate as the service account. Click the ellipsis next to the new service account and select Manage keys from the options.

    managekeys.jpg
  8. You are directed to the KEYS page of the Service accounts. Click the ADD KEY dropdown and select Create new key option.

    createnewkey.jpg
  9. Select JSON as your Key type. Click CREATE. Once you created a key here, it automatically downloads to your local machine and you can upload it to the Code Signing tab of Bitrise. You may close your Google Cloud Platform window as we won’t need it any more.

    jsonkey-png.jpg
  10. You are landing back on the API access page of Google Play Console where you can see your new service account under Service accounts. Click Grant access to link your project to the Google Console. The Google Cloud Platform (GCP) service account will be invited as a user to the Google Play Console, so GCP will have access to your apps in Play Console. Bitrise uses this service account to make changes in the Google Play Console.

    grantaccess.jpg
  11. In the Invite user window, the Email address field is pre-filled. Under Permissions, the default ones are already selected. You can go with these. Click Invite user at the bottom of the page.

    permission.jpg

Check out the Google Play Developer API 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. 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.

  2. Link your Google Play Developer Console to an API project.

  3. Set up API Access Clients using a service account: Please note when you create your service account on the Google Developer Console, you have to choose json as Key Type.

  4. Grant the necessary rights to the service account with your Google Play Console. 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.

  5. As an optional step, you can add translations to your Store Listing: Translate & localize your app.

  6. Open your app on Bitrise.

  7. Go to the Workflow tab.

  8. Go to the Code Signing tab and upload the service account JSON key into the GENERIC FILE STORAGE.

Deploying an Android app to bitrise.io

In this section, we'll go through how to deploy your Android app to bitrise.io.

Deploying to 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 app on your own test devices, for example.

To deploy your app to bitrise.io:

  1. Make sure your Workflow contains the Android Build Step to build your app.

    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.

  2. Add the Deploy to Bitrise.io Step to your Workflow.

    Tip

    You can use the Notify: User Roles and the Notify: Emails inputs of the Step to set up notifications about your deploy.

You can share the generated binary with your team members using the build’s URL.

Deploying to Google Play

Deploying to Google Play requires a signed APK or AAB file and the Google Play Deploy Step.

  1. If you're trying to deploy your app for the first time, make sure your Google Play configuration is set up correctly.

  2. Open your app on Bitrise.

  3. Go to the Workflow tab.

  4. Go to the Code Signing tab and copy the Environment Variable key which stores your uploaded the service account JSON key file’s URL.

  5. Copy the Environment Variable key which stores your uploaded file’s URL.

    For example: BITRISEIO_SERVICE_ACCOUNT_JSON_KEY_URL.

  6. Open your Workflow and add the Google Play Deploy Step to it.

  7. In the Service Account JSON key file path input, paste the Environment Variable which was generated when you uploaded the service account JSON key in the GENERIC FILE STORAGE. Besides the generated Env Var, you can also add a file path right in the Step’s input field where the file path can be local or remote too:

    • For remote JSON key file you can provide any download location as value, for example, https://URL/TO/key.json.

    • For local JSON key file you can provide a file path url as value, for example, file://PATH/TO/key.json.

  8. In the Package name input, add the package name of your app.

  9. 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).

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!