-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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.
- Inside the Google Play Store for your project, navigate to
Settings
->API Access
:
- There should be a
Service Accounts
section where you need to click theCreate Service Account button
. Click on the link shown on the first step to visit the Google Developers Console.
- Click on the
Create New Client ID
button.
- Click to create new
Service Account
. Make sure to also request the.p12 Key File
instead of JSON:
-
You will be prompted to download the
.p12
file. Save it somewhere. -
Note the service account email associated with this new account. You should see it appear in the Google Developer Console:
- Once you are done, go back to the Google Play Developer Console and navigate to the
Settings
->API Access
. Make sure the checkboxes forEdit store listing, pricing & distribution
,Manage Production APKs
, andManage 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.
If you want to be push your APKs directly through Gradle, you can install a plugin such as the Gradle Play Publisher.
- Add the following to the top of your
app/build.gradle
file:
buildscript {
repositories {
jcenter()
}
dependencies {
// ...
classpath 'com.github.triplet.gradle:play-publisher:1.1.5'
}
}
apply plugin: 'com.github.triplet.play'
- Configure the plugin with the Google Service Account and p12 file saved in steps #5 and #6.
play {
track = 'alpha'
serviceAccountEmail = 'abcd@developer.gserviceaccount.com'
pk12File = file('Google Play Android Developer-12345.p12')
}
- 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
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.
-
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.
-
Verify that you've the followed the guide about how to configure Google API access.
-
Inside Jenkins, go to
Manage Jenkins
->Manage Plugins
. Assuming the plugin has not yet been installed, select theAvailable
tab and search for theGoogle Play Android Publisher Plugin
. -
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.
- 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.
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.
- 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 theAuthentication token
(i.e. http://ci.mycompany.com/view/All/job/AndroidBuild/build?token=TOKEN_NAME) to trigger this Jenkins job.
- Go to your GitHub repository
Settings
page and visit theWebhooks & Services
section. Enter thePayload URL
for your Jenkins build job.
- You can also control which GitHub events should fire these Jenkins build jobs:
Created by CodePath with much help from the community. Contributed content licensed under cc-wiki with attribution required. You are free to remix and reuse, as long as you attribute and use a similar license.
Finding these guides helpful?
We need help from the broader community to improve these guides, add new topics and keep the topics up-to-date. See our contribution guidelines here and our topic issues list for great ways to help out.
Check these same guides through our standalone viewer for a better browsing experience and an improved search. Follow us on twitter @codepath for access to more useful Android development resources.