Updated 19 days ago | GitHub

Automating Publishing to the Play Store

The Google Play Developer API allows you to push app updates to the Play Store automatically. This ability allows you to trigger builds on your continuous integration server (i.e. Jenkins) and have them uploaded to the Play Store for testing tracks (internal, alpha, beta), as well as pushing to production directly. Note that since August 2021 new apps are required to publish with the Android App Bundle (AAB) on Google Play instead of an APK.

This guide will show you how you can setup publishing builds directly through the command-line, or how you configure a continuous integrations server such as Jenkins to do the same. Regardless of which approach, you will need to setup Google API access.

Setup for Google API access

Note: The screenshots below show an older version of the consoles. In the current flow, documented in the Play Developer API getting-started guide, you create the service account in the Google Cloud Console (with the Google Play Android Developer API enabled for that Cloud project), download a JSON key rather than a .p12 key, and then invite the service account’s email address on the Play Console’s Users and permissions page to grant it publishing access. Current tooling such as the Gradle Play Publisher plugin expects a JSON key.

  1. Inside the Google Play Store for your project, navigate to Settings -> API Access:

  1. There should be a Service Accounts section where you need to click the Create Service Account button. Click on the link shown on the first step to visit the Google Developers Console.

  1. Click on the Create New Client ID button.

  1. Click to create new Service Account. Make sure to also request the .p12 Key File instead of JSON:

  1. You will be prompted to download the .p12 file. Save it somewhere.

  2. Note the service account email associated with this new account. You should see it appear in the Google Developer Console:

  1. Once you are done, go back to the Google Play Developer Console and navigate to the Settings -> API Access. Make sure the checkboxes for Edit store listing, pricing & distribution, Manage Production APKs, and Manage Alpha & Beta APKs are checked for the Google Service account used. (If you intend to upload an alpha or beta SDK through a Google service account, apparently these permissions must be checked according to this discussion.

Setting Up Gradle Plugin (for command-line publishing)

If you want to push your builds directly through Gradle, you can install the Gradle Play Publisher plugin (currently in maintenance mode: issues are ignored, but pull requests are accepted). Note that the first version of your app must be uploaded manually through the Play Console — the plugin can only handle subsequent uploads.

  1. Apply the plugin in your app/build.gradle.kts file using the plugins { } block:
plugins {
    id("com.android.application")
    id("com.github.triplet.play") version "4.1.1"
}
  1. Configure the plugin with the JSON key of the Google service account created during the API access setup by adding a play block alongside the android one:
play {
    serviceAccountCredentials.set(file("your-key.json"))
    track.set("internal") // or "alpha", "beta", "production"; defaults to "internal"
}

Avoid committing the unencrypted key to source control: you can instead put the JSON file’s contents in the ANDROID_PUBLISHER_CREDENTIALS environment variable and omit the serviceAccountCredentials property.

  1. The plugin creates the following tasks for you:
Command Description
publishBundle Uploads the App Bundle for every variant.
publishApk Uploads the APK (and splits, if available) for every variant.
publishListing Uploads the descriptions and images for the Play Store listing.
promoteArtifact Promotes an existing release to another track.
bootstrapListing Fetch data from the Play Store & bootstrap the required files/folders

Task names follow the Android Gradle Plugin naming convention, so per-variant tasks such as publishReleaseBundle are also generated. You can now type gradle commands such as the following:

./gradlew publishBundle

Setting Up Jenkins (for automating CI builds)

This section mainly shows how to setup the Google Play Android Publisher plugin with Jenkins. You can most likely adapt the same steps for other services that enable beta distribution, such as Firebase App Distribution. (Older versions of this guide pointed at HockeyApp, which Microsoft folded into Visual Studio App Center in November 2019; App Center was itself retired on March 31, 2025.)

  1. Make sure you have already gone through the process of Building Gradle Projects with Jenkins CI and already have a Jenkins job correctly running. You will only need to install a Jenkins plugin that will allow you to create a build step that will enable the APK generated to be published to the Google Play store directly.

  2. Verify that you’ve the followed the guide about how to configure Google API access.

  3. Inside Jenkins, go to Manage Jenkins -> Manage Plugins. Assuming the plugin has not yet been installed, select the Available tab and search for the Google Play Android Publisher Plugin.

  4. Navigate to the Credentials section in Jenkins and load the service account key file downloaded during the initial setup process of setting up Google API access (the plugin recommends the JSON key type, though .p12 keys also work). A basic walkthrough video also demonstrates how to do this step.

  1. Add a post-build step to your existing Jenkins project.

   a. Make sure to choose the credential name from the drop-down list.  It should belong to the Google Play account that manages the app.

   b. Enter path and/or an [Ant-style](http://stackoverflow.com/questions/69835/how-do-i-use-nant-ant-naming-patterns) wildcard pattern for the APK.  For instance, the example in the screenshot expects the APK to be generated inside `**/build/outputs/apk/yourappname*.apk`.

   c. Choose what track to which the APKs should be deployed (Alpha, Beta, Production).

   d. You can create release notes before you start the build.  If you forget to do this step or your automated process pushes the build, you can edit them later directly on the Google Play Developer Console.

GitHub / Jenkins integration

Do not follow these steps if you intend for your Jenkins jobs to push directly to Production tracks. You should always verify your builds before rolling out to production users.

  1. Jenkins jobs can be triggered via remote API commands by sending an HTTP POST to the job’s build endpoint, authenticated with your Jenkins username and an API token (created from your personal Security configuration page) over HTTP Basic authentication:

    curl -X POST -L --user your-user-name:apiToken \
        https://ci.mycompany.com/job/AndroidBuild/build
    

    Avoid the legacy per-job Authentication token build trigger shown in older screenshots — putting a credential in the URL’s query string leaks it into proxy and access logs.

  1. Go to your GitHub repository Settings page and visit the Webhooks & Services section. Enter the Payload URL for your Jenkins build job.

  1. You can also control which GitHub events should fire these Jenkins build jobs: