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:
Let’s automate the last steps so everyone can do it.
Prerequisites
- Don’t forget to install Jenkins.
- Familiar with Jenkins Pipeline.
- You have installed Google Play Android Publisher plugin on Jenkins.
- You have created App Signing Key like
keystore.jks
before, if you haven’t done it, you can do it like this. - You have already published your app on any release track (alpha, beta or production).
- Upload your App Signing Key to PlayStore in order to enable app signing by Google Play.
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'
If it is running well, the result will be like this and you’re done in the very first step.
2. Create Google Service Account
In your Google Play Console, navigate to Settings and then to Developer account and then API access
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.
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.
Now, you’re on Google API Console dashboard and then click Create Service Account on the top of menus.
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.
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
And you need to add other credentials as Google Service Account from private key by uploading generated JSON or P12 key from previous section.
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.
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.
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.
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.
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.
On Upload Android AAB to Google Play action, there are several field that need to be filled:
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 :D