Generate production bundle for Android in Bitbucket Pipeline
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:
- The generated artifact can be downloaded from Bitbucket Pipelines — Artifact Tab
- 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. - We save the
android-signing-keystore.jks
toapp/
path but we providekeystoreFileLocation
variable without it. This is because the path is relative to the build.gradle when theproductionSigning
config is executed.
Useful Links:
- 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