Generate production bundle for Android in Bitbucket Pipeline

Ankit Gupta
Gramoday
Published in
2 min readFeb 27, 2022
Photo by Denny Müller on Unsplash

This post describes how to securely generate a signed .aab bundle for publishing to Playstore from Bitbucket Pipelines.

This can be done in 3 steps:

Step 1.

Save the below env variables in Bitbucket Deployment Variables

SIGNING_JKS_FILE — Main .jks signing key base64 encoded.

To generate base64

on Mac:

$ base64 < production.jks

on Linux:

$ base64 -w 0 < production.jks

SIGNING_KEYSTORE_PASSWORD — Key store password

SIGNING_KEY_PASSWORD — Key password

SIGNING_KEY_ALIAS — Alias for the signing key

Step 2.

Update the build.gradle file to add the productionSigning config as below.

We are trying to read from the keystore.properties file which we will create dynamically in the below pipeline.

Step 3.

Create bitbucket-pipelines.yml with the below custom pipeline

Few things to note:

  1. The generated artifact can be downloaded from Bitbucket Pipelines — Artifact Tab
  2. We have used size: 2x since the generation requires more cpu and will take lesser time. This does incur twice as much billing on the pipeline minutes.
  3. We save the android-signing-keystore.jks to app/ path but we provide keystoreFileLocation variable without it. This is because the path is relative to the build.gradle when the productionSigning config is executed.

Useful Links:

  1. We can take this a step further and publish them directly to the Google Playstore tracks. This requires a Google cloud publishing key along with the Playstore Signing Key.

2. While automating this, one might want to automatically bump up the version in the build.gradle

--

--