This blog post shows how to automate publishing to Google Play Store with Gradle Play Publisher. The goal is to automate the manual process of uploading Apk andBundle files, and also release notes to the Google Play Store. First time publishing the APK it's a manual process.
Publish App Bundle:
- Create a new Service account. (Microsoft did a nice tutorial for generating a service account). In this step, we will create and download a .p12 or JSON file key. Add the key file to your project inside gradle.properties:
GOOGLE_ACCOUNT_SERVICE_FILE=/home/gradle/TuneIn/Tunein-Android-Play-Publish.json
(don't check in file key to Github add it to .gitignore, or add the key file at build time).
2. Add below code snippet to build.gradle (app). More details here (note below code needs to go on the top of the file).
plugins {
id 'com.android.application'
id 'com.github.triplet.play' version '2.1.0'
}
3. Also, add below code to build.gradle (app). The configuration below uploads APK or Bundle files to the Internal test track.
android {
....
play {
track = 'internal' //'alpha','beta' or 'production'
serviceAccountEmail = "[email protected]"
serviceAccountCredentials = file(p12_KEY)
}
...
}
4. Configuration is done, now to publish Bundle or APK to Google Play Store using below commands:
Publish App Bundle
./gradlew publishBundle
Publish APK:
./gradlew publishApk
Note: remember to update your App Version code or you will get publish error:
* What went wrong:
Execution failed for task ':app:publishReleaseBundle'.
> Version code 45 is too low for variant release.
Publish App Bundle and Release notes:
- The same configuration as above steps, you just need to create a new file "default.txt" → app/src/main/play/release-notes/en-US/default.txt.
- Add your release notes in default.txt.
- To publish Bundle and the release notes we use the same command that we use to upload Bundle.
Publish App Bundle and Release notes:
./gradlew publishBundle
Production rollout by percentage
Use options track = "production", "userFraction" and "releaseStatus" to rollout by percentage in Production track.
android {
play {
track = "production"
userFraction = 0.5 //case default is 0.1 (10% of the target)
releaseStatus = "inProgress"
serviceAccountEmail = "mympp471651.iam.gserviceaccount.com"
serviceAccountCredentials = file(p12_KEY)
}
Check GPP configuration:
GPP adds Publishing Gradle tasks to your project, run ./gradlew tasks --all
Ping me if you have any questions. Thanks for reading!
Resources:
Notes:
- Create a new Service account.
- Go to developer account -> API access -> enable access "Release Manager" permission.