Gradle Play Publisher
Gradle Play Publisher (GPP) is Android's unofficial release automation Gradle Plugin. It can do anything from building, uploading, and then promoting your App Bundle or APK to publishing app listings and other metadata.
Project status: maintenance mode
Issues are ignored, but pull requests are not. If you need to get something done, submit a PR!
Table of contents
- Quickstart guide
- Prerequisites
- Basic setup
- Task organization
- Managing artifacts
- Managing Play Store metadata
- Working with product flavors
- Advanced topics
Quickstart guide
- Upload the first version of your APK or App Bundle using the Google Play Console
- Create a Google Play Service Account
- Sign your release builds
with a valid
signingConfig - Add and apply the plugin
- Authenticate GPP
Prerequisites
Initial Play Store upload
The first APK or App Bundle needs to be uploaded via the Google Play Console because registering the app with the Play Store cannot be done using the Play Developer API. For all subsequent uploads and changes, GPP may be used.
Signing configuration
To successfully upload apps to the Play Store, they must be signed with your developer key. Make sure you have a valid signing configuration.
Service Account
To use GPP, you must create a service account with access to the Play Developer API:
- If you don't already have one, create a GCP project for your app(s)
- Enable the AndroidPublisher API for that GCP project
- Create a
service account and key
- Make sure you're in the GCP project you used above (check the
projectquery param in the URL) - Select
New service account - Give it a name and the Project Owner role (don't worry, we'll remove this later)
- After creating the service account, find it in the list of all service accounts and use the 3
dots menu to
Manage keys - From there, create a new key using the
Add keymenu (leave JSON selected)
- Make sure you're in the GCP project you used above (check the
- Move the downloaded JSON credentials into your project and tell GPP about it
- Give your service account
permissions to publish apps
on your behalf
- Click
Invite new user - Copy/paste the service account email (you can find it in the JSON credentials)
- Don't touch the roles
- Specify which apps the service account should have access to. In this example, GPP has full access to testing tracks and app listings, but will be unable to make production releases:
- Click
6. Run `./gradlew bootstrapListing` or some other GPP task to validate your setup
7. Now that you've successfully created the connection between GCP and Google Play, you can remove
the Project Owner permissions
1. Go to your [IAM settings](https://console.cloud.google.com/iam-admin/iam)
2. Search for the service account you created
3. Click the edit icon (found at the end of the row)
4. In the permission selection panel that opens, click the trash icon to remove the owner role
5. Click saveBasic setup
Installation
Apply the plugin to each individual com.android.application module where you want to use GPP
through the plugins {} DSL:
Kotlin
plugins {
id("com.android.application")
id("com.github.triplet.play") version "4.1.1"
}
Groovy
plugins {
id 'com.android.application'
id 'com.github.triplet.play' version '4.1.1'
}
Snapshot builds
If you're prepared to cut yourself on the bleeding edge of GPP development, snapshot builds are
available from
Sonatype's snapshots repository:
Kotlin
buildscript {
repositories {
// ...
maven("https://oss.sonatype.org/content/repositories/snapshots")
}
dependencies {
// ...
classpath("com.github.triplet.gradle:play-publisher:5.0.0-SNAPSHOT")
}
}
Groovy
buildscript {
repositories {
// ...
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}
dependencies {
// ...
classpath 'com.github.triplet.gradle:play-publisher:5.0.0-SNAPSHOT'
}
}
Authenticating Gradle Play Publisher
After you've gone through the Service Account setup, you should have a JSON file
with your private key. Add a play block alongside your android one with the file's location:
android { ... }
play {
serviceAccountCredentials.set(file("your-key.json"))
}
Note: If you commit unencrypted Service Account keys to source, you run the risk of letting anyone access your Google Play account. To circumvent this issue, put the contents of your JSON file in the
ANDROID_PUBLISHER_CREDENTIALSenvironment variable and don't specify theserviceAccountCredentialsproperty.
Application Default Credentials
Alternatively, you can use Application Default Credentials (and optionally Service Account impersonation) instead of specifying a JSON private key file or environment variable:
android { ... }
play {
useApplicationDefaultCredentials = true
impersonateServiceAccount = "[email protected]" // Optional
}
Note: Currently, Service Account impersonation is only supported when using Application Default Credentials.
Task organization
GPP follows the Android Gradle Plugin's (AGP) naming convention: [action][Variant][Thing]. For
example, publishPaidReleaseBundle will be generated if you have a paid product flavor.
Lifecycle tasks to publish multiple product flavors at once are also available. For example,
publishBundle publishes all variants.
To find available tasks, run ./gradlew tasks --group publishing and use
./gradlew help --task [task] where task is someth