For uploading APK to google play automatically, we can either use the API’s provided by google itself to manually upload APK or use an existing solution. Good thing for us is that there is already an existing open source gradle plugin for publishing apps to google play, so we don’t need to get our hands dirty.
The plugin we are going to use is named gradle play publisher that will automate all this stuff for us.
Including the plugin in your project
Add this to your project level build.gradle file.
And, in your app (or module) level build.gradle file.
You can also modify the play
section according to your own needs.
Here is the description about properties used in play
section.
Property | Description |
---|---|
track | Defines on which channel the APK should be published. Can be one of the production, beta, alpha or rollout. |
userFraction | Rollout the APK for some users only. Default value is 0.1 (which means 10%). This property is necessary if you are publishing with track = 'rollout' . |
untrackOld | Doesn’t track for old APKs for version conflicts. |
errorOnSizeLimit | Plugin checks if the provided details like title, short description, long description and recent changes are not exceeding their required limit. You can disable this check by setting this property to false. By default it is true. |
uploadImages | Upload images for Google Play Store listing. By default it is false. |
PS: In the previous blog post we discussed about how to create a service account and json key file. These properties are required inorder to authenticate with your google play account. Please check the previous blog to know more about these properties.
Preparing for release 🚀
Inorder to prepare a release, first we need to setup the appropriate metadata which will be used by the plugin.
You can either create these directories and files manually or use this gradle task to create them automatically. Make sure you are in your project directory while running this command.
This would create all the resources required in order to publish your APK.
Play Store Metadata Structure
- [src]
|
+ - [main]
|
+ - [play]
|
+ - [en-US] -> Locale in which your content would be published
| |
| + - [listing] -> Details about play store listing
| | |
| | + - fulldescription
| | |
| | + - shortdescription
| | |
| | + - title
| | |
| | + - video
| |
| + - whatsnew -> For showing changelog/features of the latest update
|
+ - [de-DE]
| |
| + - [listing]
| | |
| | + - fulldescription
| | |
| | + - shortdescription
| | |
| | + - title
| | |
| | + - video
| |
| + - whatsnew
|
+ - contactEmail
|
+ - contactPhone
|
+ - contactWebsite
|
+ - defaultLanguage -> Default locale for publishing. (For example: en-US)
For more info about play store metadata, check the plugin’s readme section.
After setting it up, we can finally publish the app using this plugin.
This command will create a signed APK for your project and then publish it on google play with the summary of recent changes (whatsnew). Your release would now be available on Google Play Developer Console. Just check it once to make sure it release was successful or not.
PS: Make sure to bump up versionCode and versionName in your build.gradle
file.
Gradle tasks provided by this plugin
Task | Description |
---|---|
publishApkRelease | Uploads signed APK and the summary of recent changes. |
publishListingRelease | Uploads only images and description. |
publishRelease | Uploads everything including signed APK, recent changes, images and description. |
bootstrapReleasePlayResources | Retrieves current listing details from Google Play and assemble it properly in directories and files (metadata). |
That’s it for now folks. Now, you know how to publish signed APK with just a single gradle task. In next part, we will learn how to integrate CI and move the publishing part to CI.