Automating Android Bundle Publish to Google Play Console | by Surya Prakash | Aug, 2023
Automating Android Bundle Publish to Google Play Console | by Surya Prakash | Aug, 2023

This article chronicles my journey in establishing a way to automate Android Gradle Build Publish to Google Play Console using “Gradle Play Publisher Plugin” as a prime option for streaming this process.

While various approaches were available like using Developer Console for Google Play provides API, we opted for this particular approach due to its simplicity and ease of implementation process.

Plugins is nothing but set of all useful tasks, such as compiling tasks, setting domain objects, setting up source files, etc, applying a plugin to a project allows the plugin to extend the project’s capabilities.

Likewise, Gradle Play Publisher Plugin allows you to upload your App Bundle or APK and also promoting your App Bundle or APK to publishing app listings and other metadata to Google Play Store

Source: https://plugins.gradle.org/plugin/com.github.triplet.play

To use GPP (Gradle Play Publisher), you must create a service account with access to the Play Developer API:

  1. Inside the Google Play Console for your project, navigate to Settings -> API Access:
  2. There should be a Service Accounts section where you need to click the Create Service Account button
  3. Click on the Create New Client ID button.
  4. Click to create new Service Account. Make sure to also request the json key fileinstead of .p12 and provide the owner role permissions to it ( assuming it as admin service account)
  5. You will be prompted to download the json file. Save it somewhere.
  6. Once the above access setup is completed,

You can run “./gradlew bootstrapListing” command to validate your setup.

Note: Running this command with “— debug” option will allow you to troubleshoot incase of any errors with more detail logs

Apply the plugin to each individual com.android.application module where you want to use GPP as below in your project level build.gradle:

Kotlin:

apply plugin: 'com.android.application'
apply plugin: 'com.github.triplet.play'

buildscript
repositories
// ...
maven("https://plugins.gradle.org/m2/")

dependencies
// ...
classpath('com.github.triplet.gradle:play-publisher:3.7.0')

Groovy:

apply plugin: 'com.android.application'
apply plugin: 'com.github.triplet.play'

buildscript
repositories
// ...
maven url "https://plugins.gradle.org/m2/"

dependencies
// ...
classpath 'com.github.triplet.gradle:play-publisher:3.7.0'

After you’ve gone through the service account setup process, you should have a JSON file with your private key. Add a play block alongside your android one with the file’s location as below:

play 
serviceAccountCredentials.set(file("android_publisher.json"))
track.set("alpha")
defaultToAppBundles.set(true)
artifactDir.set(file("path/to/app-bundle.aab"))

If you are working with different product flavours:

android 

productFlavors
create(myCustomStgVariant)


create(myCustomProdVariant)


playConfigs
register(myCustomStgVariant)
track.set("alpha")
artifactDir.set(file("path/to/stg-app-bundle.aab"))
defaultToAppBundles.set(true)
serviceAccountCredentials.set(file("android_publisher.json"))

register(myCustomProdVariant)
track.set("alpha")
artifactDir.set(file("path/to/prod-app-bundle.aab"))
defaultToAppBundles.set(true)
serviceAccountCredentials.set(file("android_publisher.json"))


  • track is the target stage for an artifact, i.e. internal/alpha/beta/production or any custom track. Defaults to internal
  • By default, it uploads an APK by default. To change this, we use “defaultToAppBundles”
  • By default, GPP will build your artifact from source but you specify a directory in which publishable artifacts may be found by using “artifactDir.set”

Once we configure the GPP plugin, it creates the following tasks for you:

You can run command “./gradlew tasks” to view the GPP tasks

Once we complete the gradle configuration, now we can use GPP tasks to publish the artifact to google play console. GPP supports uploading both the App Bundle and APK.

Below are some of tasks created by Gradle Play Publisher plugin:

GPP follows the Android Gradle Plugin’s (AGP) naming convention: [action][Variant][Thing]For example, publishProdReleaseBundle will be generated if you have a prod product flavor.

Lifecycle tasks to publish multiple product flavors at once are also available. For example, publishBundle publishes all variants.


./gradlew publishBundle - Publishing an App Bundle all variants

./gradlew publishApk - Publishing APKs all variants

./gradlew publishStgReleaseBundle - Publish Stg release variant App Bundle

./gradlew publishsProdReleaseBundle - Publish prod release variant App Bundle

./gradlew publishStgApk - Publish stg release variant APK

./gradlew publishProdApk - Publish prod release variant APK

Note: Incase of any errors while publishing artifact, you can enable debug logs by using “ — debug” parameter

Once uploaded, GPP also supports in promoting those artifacts to different tracks in Play Console.

To configure this feature, you can use the fromTrack property:

Similarly, the track to which to promote a release defaults to the promoteTrack property. If unspecified, the resolved fromTrack property will be used instead and an in-place update will be performed. Example configuration:

play 
// ...
fromTrack.set("alpha")
play 
// ...
promoteTrack.set("beta")

Beyond the scope of this article, there exist a multitude of untapped capabilities within GPP that can further enhance your publishing workflow. To explore these additional features and expand your knowledge, I encourage you to delve into the official GitHub repository of GPP.

By leveraging these features, you can not only save time and effort but also ensure a seamless and efficient journey from artifact creation to the Play Console.

If you like this post. Please show support by clicking clap.

By