Skip to main content

Generating and deploying Android app bundles

Abstract

Creating an Android App Bundle with Bitrise is almost the same as generating an APK. You have to tweak a few Step inputs to compile an Android App Bundle (.aab) file from your code, then get the bundle signed and deployed to Google Play Store.

Creating an Android App Bundle with Bitrise is almost the same as generating an APK. All you have to do is tweaking a few Step inputs to compile an Android App Bundle (.aab) file from your code, then get the bundle signed and deployed to Google Play Store.

Step versions supporting bundle creation

The following Steps must be of the indicated version or newer - older versions of the Steps do NOT support bundle creation.

  • Android Build 0.10.0 or newer

  • Gradle Runner 1.9.0 or newer

  • Android Sign 1.3.0 or newer

  • Deploy to Google Play 1.6.0 or newer

Generating an Android App Bundle file

You can create an Android App Bundle with either the Gradle Runner Step or with the Android Build Step.

Using the Gradle Runner Step

Workflow Editor

bitrise.yml

  1. Log in to Bitrise and select Bitrise CI on the left, then select your project.

  2. Click the Workflows button on the main page.

  3. Insert the Gradle Runner Step after the Android Unit Test and Android Lint Steps in your Workflow.

  4. Click the Config section of Gradle Runner.

  5. In the Gradle task to run input field, set, for example, bundleRelease or bundleDebug to create a bundle of your project.

    Generating and deploying Android app bundles

    APK and AAB in the same Workflow

    If you wish to generate an Android App Bundle and an APK in one Workflow, you can specify an additional task in the Gradle task to run input field: set the input value to bundleRelease assembleRelease to generate release versions.

  1. Open the bitrise.yml file of your app.

  2. Insert the gradle-runner Step after the android-unit-test and android-lint Steps in your Workflow.

    my-workflow:
      steps:
        - activate-ssh-key:
            run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
        - git-clone: {}
        - install-missing-android-tools: {}
        - android-lint: {}
        - android-unit-test: {}
        - gradle-runner:
  3. In the gradle_task input of gradle-runner, set, for example, bundleRelease or bundleDebug to create a bundle of your project.

    my-workflow:
      steps:
        - activate-ssh-key:
            run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
        - git-clone: {}
        - install-missing-android-tools: {}
        - android-lint: {}
        - android-unit-test: {}
        - gradle-runner:
            inputs:
              - gradle_task: bundleRelease

    APK and AAB in the same Workflow

    If you wish to generate an Android App Bundle and an APK in one Workflow, you can specify an additional task in the gradle_task input field: set the input value to bundleRelease assembleRelease to generate release versions.

This way the Step will generate an Android App Bundle instead of an APK.

Using the Android Build Step

You can generate an Android App Bundle for your Android app with our Android Build Step as well:

Workflow Editor

bitrise.yml

  1. Log in to Bitrise and select Bitrise CI on the left, then select your project.

  2. Click the Workflows button on the main page.

  3. Add the Android Build Step after the Android Unit Test and Android Lint Steps in your Workflow.

  4. Provide the root directory of your Android project in the Project Location input field.

  5. Go to Build type and select aab as build type.

    Generating and deploying Android app bundles

    APK and AAB in the same Workflow

    If you wish to generate an APK and an Android App Bundle in one Workflow, add two Android Build Steps after each other and configure one to build an Android App Bundle and the other to build an APK.

  1. Open the bitrise.yml file of your app.

  2. Add the android-build Step after the android-unit-test and android-lint Steps in your Workflow.

    my-workflow:
      steps:
        - activate-ssh-key:
            run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
        - git-clone: {}
        - install-missing-android-tools: {}
        - android-lint: {}
        - android-unit-test: {}
        - android-build:
    
  3. Provide the root directory of your Android project in the project_location input field.

  4. Set the value of the build-type input to aab.

    my-workflow:
      steps:
        - activate-ssh-key:
            run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
        - git-clone: {}
        - install-missing-android-tools: {}
        - android-lint: {}
        - android-unit-test: {}
        - android-build:
            inputs:
              - build-type: aab

    APK and AAB in the same Workflow

    If you wish to generate an APK and an Android App Bundle in one Workflow, add two android-build Steps after each other and configure one to build an Android App Bundle and the other to build an APK.

Signing an Android App bundle

Signing an Android App Bundle file works the same way as signing an APK: the most convenient method is to upload your keystore files to Bitrise and use the Android Sign Step:

Workflow Editor

bitrise.yml

  1. Upload your keystore file to Bitrise.

  2. Open your Workflow in the Workflow Editor, and add the Android Sign Step AFTER the build Step.

  3. Make sure that the Keystore password, Key alias and the Key password input fields are filled out.

    Default input values

    If you have uploaded your keystore file and filled out the required credentials, the Android Sign Step's Keystore url, Keystore password, Keystore alias, and the Private key password inputs will get populated automatically!

  4. Make sure the App file path input field displays the same output env var as the output of the build Step you've been using.

    For example, Android Build exports either a $BITRISE_APK_PATH or a $BITRISE_AAB_PATH Env Var that points to the APK and/or AAB file the Step generated. By default, this input points at these Env Vars.

    Generating and deploying Android app bundles

    Further configuration options

    Check out all the available configuration options of the Android Sign Step in the Workflow Editor. You can:

    • Enable or disable memory page alignment with the Page alignment input.

    • Use apksigner instead of the default jarsigner with the Enables apksigner input.

    • Enforce a specific Signature Scheme with the APK Signature Scheme input.

  1. Upload your keystore file to Bitrise.

  2. In your app's bitrise.yml file, add the sign-apk Step AFTER the build Step - for example, android-build - in your Workflow.

    sign-android-workflow:
      steps:
        - android-build: {}
        - sign-apk@1:
            inputs:
    
  3. Make sure that the keystore_url, keystore_password, and keystore_alias inputs point to the correct location.

    sign-android-workflow:
      steps:
        - android-build: {}
        - sign-apk@:
            inputs:
            - keystore_url: "$BITRISEIO_ANDROID_KEYSTORE_URL"
            - keystore_password: "$BITRISEIO_ANDROID_KEYSTORE_PASSWORD"
            - keystore_alias: "$BITRISEIO_ANDROID_KEYSTORE_ALIAS"
    

    Default input values

    If you have uploaded your keystore file to Bitrise and filled out the required credentials, you do not have to set the inputs at all: the default values, defined in the Step's step.yml configuration file, will point to the keystore file and the necessary credentials.

  4. Make sure the android_app input field displays the same output Env Var as the output of the build Step you've been using.

    For example, android-build exports either a $BITRISE_APK_PATH or a $BITRISE_AAB_PATH Env Var that points to the APK and/or AAB file the Step generated. By default, this input points at these Env Vars.

    The Step will look for a binary to sign at the locations provided in this input.

    sign-android-workflow:
      steps:
        - android-build: {}
        - sign-apk@1:
            inputs:
            - keystore_url: "$BITRISEIO_ANDROID_KEYSTORE_URL"
            - keystore_password: "$BITRISEIO_ANDROID_KEYSTORE_PASSWORD"
            - keystore_alias: "$BITRISEIO_ANDROID_KEYSTORE_ALIAS"
            - android_app: "$BITRISE_APK_PATH\\n$BITRISE_AAB_PATH"
    

    Further configuration options

    Check out all the available configuration options of the android-sign Step in its step.yml file. You can:

    • Enable or disable memory page alignment with the page_align input.

    • Use apksigner instead of the default jarsigner with the use_apk_signer input.

    • Enforce a specific Signature Scheme with the signer_scheme input.

And you should be done! If you would like to read more about Android code signing, check out our guide.

Deploying your Android App Bundle to Google Play

Deploying an AAB file isn't significantly different from deploying an APK to Google Play.

If you want to check the bundle prior to app store distribution, you can add the Deploy to Bitrise.io Step after the Gradle Runner / Android Build Steps. It uploads the bundle into the Artifacts tab of your Build’s page.

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. Connect your Google service account to Bitrise.

Deploying to Google Play

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

Workflow Editor

bitrise.yml

  1. If you're trying to deploy your app for the first time, make sure your Google Play configuration is set up correctly and that you uploaded your service account JSON key to Bitrise.

    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.

  2. Open the App settings page, and select Code Signing.

  3. On the Android tab, find the uploaded service account JSON key and copy the secret Env Var under its name.

    For example, BITRISEIO_SERVICE_ACCOUNT_JSON_KEY_URL.

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

  5. In the Service Account JSON key file path input, paste the Environment Variable you copied.

    Direct path to the service account JSON key file

    If you don't want to upload the service account JSON key to Bitrise, 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 a remote JSON key file you can provide any download location as value, for example, https://URL/TO/key.json.

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

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

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

  1. If you're trying to deploy your app for the first time, make sure your Google Play configuration is set up correctly and that you uploaded your service account JSON key to Bitrise.

    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.

  2. Open your app's bitrise.yml file and add the google-play-deploy Step to it.

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

    If you uploaded the file to Bitrise, you can find the Env Var storing its download URL in the Generic File Storage in the Workflow Editor.

    deploy-workflow:
      steps: 
      - google-play-deploy: 
          inputs:   
          - service_account_json_key_path: "$BITRISEIO_SERVICE_ACCOUNT_JSON_KEY_URL"

    If you didn't upload your service account JSON key to Bitrise, you can set a direct path in the input. The file path can point to a local or a remote location.

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

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

  4. In the package input, add the package name of your app.

    deploy-workflow:
      steps: 
      - google-play-deploy: 
          inputs:   
          - service_account_json_key_path: "$BITRISEIO_SERVICE_ACCOUNT_JSON_KEY_URL"
          - package_name: myApp
  5. 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).

    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!