Automating Publishing to the Play Store

The Developer Console for Google Play provides API support for you to be able to push to the store automatically. This ability allows you to trigger builds on your continuous integration server (i.e. Jenkins) and have them uploaded the Play store for alpha or beta testing, as well as pushing to production directly.

This guide will show you how you can setup publishing APK's 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

  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 APK publishing)

If you want to be push your APKs directly through Gradle, you can install a plugin such as the Gradle Play Publisher.

  1. Add the following to the top of your app/build.gradle file:
  buildscript {
     repositories {
     dependencies {
         // ...
         classpath 'com.github.triplet.gradle:play-publisher:1.1.5'

 apply plugin: ''
  1. Configure the plugin with the Google Service Account and p12 file saved in steps #5 and #6.

         play {
            track = 'alpha'
            serviceAccountEmail = ''
            pk12File = file('Google Play Android Developer-12345.p12')
  2. The plugin creates the following tasks for you:

Command Description
publishApkRelease Uploads the APK and the summary of recent changes.
publishListingRelease Uploads the descriptions and images for the Play Store listing.
publishRelease Uploads everything.
bootstrapReleasePlayResources Fetch data from the Play Store & bootstrap the required files/folders

You can now type the following gradle commands such as the following:

./gradlew publishApkRelease

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 and have a related plugin, such as the one for Hockey.

  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 .p12 key file downloaded during the initial setup process of setting up Google API access. A basic walkthrough video also demonstrates how to do this step.

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

link to img

   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]( 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. Setup a Build Trigger in your Jenkins job to allow builds to be triggered via remote API commands. You can use the URL shown below the Authentication token (i.e. to trigger this Jenkins job.

  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:

Fork me on GitHub