Automate Your Android App Bundle Publishing using Jenkins

As the software development team grows, we have to always keep an eye of what we could improve to make the process more efficient. In this modern era, the team usually consists of software engineers, test engineers, UI/UX designers, product managers and many more. And within the team there are various process that need to be done before releasing features on app, such as:

  1. Android engineers will develop features and also write unit and instrumentation test associated with these features.
  2. After all tests from android engineers have passed, test engineers will run their regression test and also test new features.
  3. When all tests of each stage have passed, android engineers have to build an APK or App Bundle and then publish it to google PlayStore.

Let’s automate the last steps so everyone can do it.

Prerequisites

1. Build Signed App Bundle

First, you need to make sure you have put the right thing on gradle signingConfigs and use the same keystore.jks that you have generated before.

signingConfigs {
release {
File fileProp = file(System.getenv('HOME') + "/.appkey")
if (fileProp.exists()) {
Properties releaseConfig = new Properties()
releaseConfig.load(new FileInputStream(fileProp))
storeFile file(System.getenv('HOME') + "/" + releaseConfig["KEYSTORE_FILE"])
storePassword releaseConfig['KEYSTORE_PWD']
keyAlias releaseConfig['KEY_ALIAS']
keyPassword releaseConfig['KEY_PASSWORD']
}
}
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'androiddebug'
}
}

After that, you could create build stage on your job to build signed App Bundle based on the config.

stage("Build") {
steps {
script {
sh(script: "./gradlew clean :app:bundleRelease :app:assembleRelease",
returnStdout: true)
}
}
}

In our case, sometimes we need to archive the APK for testing purpose or selecting the best release candidate to be promoted to alpha/beta track.

stage("Archive Artifacts") {
steps {
script {
archiveArtifacts allowEmptyArchive: true,
artifacts: '**/*.apk, **/*.aab, app/build/**/mapping/**/*.txt, app/build/**/logs/**/*.txt' cleanWs()
}
}
}

If it is running well, the result will be like this and you’re done in the very first step.

The result of app-artifact-release job

2. Create Google Service Account

In your Google Play Console, navigate to Settings and then to Developer account and then API access

API access menu on Google Play Console

After that click on Create New Project button, then a project on Google API Console that linked to Google Play Console account will be created.

After that click on Create New Project button, then a project on Google API Console that linked to Google Play Console account will be created.

After you clicked on create new project button

You can create a service account on Google API Console, by clicking Create Service Account and after that it will prompt a dialog consist of Google API Console link.

Prompt after clicking create service account button

Now, you’re on Google API Console dashboard and then click Create Service Account on the top of menus.

Google API Console dashboard

Fill Service account name and Service account description based on your preference, but in our case we use it for Jenkins only. Service account ID that censored below will be automatically generated.

Create service account steps

On the last steps, click Create Key on the bottom of the page to generate a private key.

Yeay! you have generated JSON or P12 file that will be used as Credentials on Jenkins for the next step.

3. Upload the Those File on Jenkins Credentials

Go to your Jenkins and navigate to Credentials and then System and then Add Credentials . Choose kind as Secret file , fill ID and Description , and don’t forget to upload your keystore.jks

Upload your keystore.jks as a secret file

And you need to add other credentials as Google Service Account from private key by uploading generated JSON or P12 key from previous section.

Add credential for uploading App Bundle or APK to Google Play Store

4. Create a Job for Uploading the Signed App Bundle

You’re almost done! The final process is to create a job to upload your App Bundle to Google Play Store. First, we can add a build step to copy signed Android App Bundle artifact from the project that we create on the first step.

Add build step to copy artifact from another project

Unfortunately, Google Play Android Publisher Plugin doesn’t seem to support the ability to upload Android App Bundle. At the moment, they only support uploading APKs.

But wait, there is more!

We are trying to modify the plugin and add a new post build action to upload Android App Bundle.

https://github.com/jenkinsci/google-play-android-publisher-plugin/pull/15

https://github.com/andrewjapar/google-play-android-publisher-plugin

To use it, you can clone the project and run mvn install script. After installation finished, you will see .hpi file in your project. After that, you can go to Manage Jenkins and then Manage Plugins , choose Advance tab and scroll down to Upload Plugins section.

Choose advance tab to upload plugins

Here we are, we can upload the .hpi file to replace the current Google Play Publisher plugin with the modified one. After that, you are required to restart Jenkins to apply the modification.

Upload plugin section

After Jenkins is restarted, a new post build action will be displayed as Upload Android AAB to Google Play menu then you could try to use it.

A new post build action to upload Android App Bundle
Post build action to upload AAB

On Upload Android AAB to Google Play action, there are several field that need to be filled:

  1. Google Service Account credential that we upload on step 3 will be displayed on the dropdown box.
  2. Signed Android App Bundle filename path pattern from previous project.
  3. Your application ID
  4. Release track (internal, alpha, beta, production)

Finally, we are successfully upload Android App Bundle to Google Play Store. Later on Jenkins will automate the boring stuff for us.


I believe there are a lot of improvements that could be done in the future and this article might not be the perfect one. If you guys have any suggestion or any feedback, please let me know. I am eager to learn more from you guys 😀

Related Posts

Streaming Festival Disrupto Exploration and Experimentation 2020

Streaming Festival Disrupto Exploration and Experimentation 2020

Resiko Berbahaya menggunakan VPN gratisan di Laptopmu!

Resiko Berbahaya menggunakan VPN gratisan di Laptopmu!

Part II — Understanding about RuleChain

Mengenal dasar RxSwift

No Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Tags