Triple-T/gradle-play-publisher


Source link: https://github.com/Triple-T/gradle-play-publisher

gradle-play-publisher

Gradle plugin to upload your APK and app details to the Google Play Store.

Quick Start Guide

  1. Upload the first version of your APK using the web interface.
  2. Create a Google Play Service Account (see Prerequisites).
  3. Assign a valid signingConfig to your release build type.
  4. Add the plugin to your buildscript dependencies (see Usage).
  5. Apply the plugin (see Usage).
  6. Create playAccountConfigs and add them to your build (see Authentication).

Prerequisites

Initial Play Store Upload

The first APK of your App needs to be uploaded via the web interface. This is to register the application id and cannot be done using the Play Developer API. For all subsequent uploads and changes this plugin can be used.

Google Play Service Account

To use the publisher plugin you have to create a service account for your existing Google Play Account. See https://developers.google.com/android-publisher/getting_started for more information.

Due to the way the Google Play Publisher API works, you have to grant at least the following permissions to that service account:

Once you finished the setup you have a so called service account email address and a p12 key file that we will use later on.

Signing Configuration

Please make sure to assign a valid signing configuration to your release build type. Otherwise, there won't be a publishable (signed) APK. In that case, the plugin won't create any of its tasks.

Usage

Add it to your buildscript dependencies (top-level build.gradle file):

buildscript {

repositories {

mavenCentral()
  
}

dependencies {

// ...

classpath 'com.github.triplet.gradle:play-publisher:1.2.0'
  
}
 
}

Apply it to your app-level build.gradle file as following below

apply plugin:'com.android.application' apply plugin: 'com.github.triplet.play'

The plugin creates the following tasks for you:

  • 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 - Fetches all existing data from the Play Store to bootstrap the required files and folders.

Make sure to set a valid signingConfig for the release build type. Otherwise, there won't be a publishable APK and the above tasks won't be available.

In case you are using product flavors you will get one of the above tasks for every flavor. E.g. publishApkPaidRelease or publishListingPaidRelease.

Authentication

Similar to Android's signingConfigs you need to setup so called playAccountConfigs to authorize your requests. Drop in your service account email address and the p12 key file you generated in the API Console here.

android {

  playAccountConfigs {

defaultAccountConfig {

 serviceAccountEmail = 'your-service-account-email'

 pk12File = file('key.p12')

}

  
}

 defaultConfig {

// ...

playAccountConfig = playAccountConfigs.defaultAccountConfig
  
}
 
}

Alternatively you can use a JSON file that can be generated in the API Console.

android {

  playAccountConfigs {

defaultAccountConfig {

 jsonFile = file('keys.json')

}

  
}

 defaultConfig {

// ...

playAccountConfig = playAccountConfigs.defaultAccountConfig
  
}
 
}

Configuration

Once you have applied this plugin to your android application project you can configure it via the play block.

Specify the track

As a default your APK is published to the alpha track and you can promote it to beta or production manually. If you want to directly publish to another track you can specify it via the track property:

play {

  // ...
  track = 'production' // or 'rollout' or 'beta' or 'alpha'
  userFraction = 0.2 // only necessary for 'rollout', in this case default is 0.1 (10% of the target) 
}

When defining the track as (staged) rollout you can also define a userFraction which is the portion of users who should get the staged rollout version of the APK.

Untrack conflicting versions

The Google Play Developer API does not allow us to publish a beta version if there is an alpha version with a lower version code. If you want to publish to higher track and automatically disable conflicting APKs from a lower track, this can be specified by setting the untrackOld property to true.

play {

  // ...
  track = 'beta'
  untrackOld = true // will untrack 'alpha' while upload to 'beta' 
}

This will untrack whatever versions are currently blocking the publishing process. That is: every APK with a version lower than the one being uploaded in any of the tracks lower than specified by track.

Example: Publishing an APK with version 42 to production will untrack versions 41 and lower from alpha and beta. It will not, however untrack versions 43 or higher from those channels because they do not conflict.

Setting that flag to false or not setting it at all will stop the publishing process in case of conflicts. Keep that behaviour if you want to manually untrack conflicting versions rather than doing automatic untracking.

Play Store Metadata

You can also update the Play Store Metadata automatically along with your APK.

To use this feature, create a special source folder called play. Inside of it, create a folder for each locale you want to support. Then drop your summary of recent changes into a file called whatsnew. The title, the description, the short description and the YouTube video url go into their own files in a subfolder called listing. App details like contact email or the default language have their own files right inside the play folder as those details are not translated. Once set up, your project should look something like this:

- [src]
|
+ - [main]

 |

 + - [play]

  |

  + - [en-US]

  |
|

  |
+ - [listing]

  |
|
|

  |
|
+ - fulldescription

  |
|
|

  |
|
+ - shortdescription

  |
|
|

  |
|
+ - title

  |
|
|

  |
|
+ - video

  |
|

  |
+ - whatsnew

  |

  + - [de-DE]

  |
|

  |
+ - [listing]

  |
|
|

  |
|
+ - fulldescription

  |
|
|

  |
|
+ - shortdescription

  |
|
|

  |
|
+ - title

  |
|
|

  |
|
+ - video

  |
|

  |
+ - whatsnew

  |

  + - contactEmail

  |

  + - contactPhone

  |

  + - contactWebsite

  |

  + - defaultLanguage 

Note: You can provide different texts for different locales, build types and product flavors. You may even support additional locales for some build types or product flavors.

It is also possible to provide a separate summary of recent changes for each track. Just drop in a special whatsnew-alpha text file alongside your main whatsnew file and that one will be used if you publish to the alpha track.

Text requirements

To make sure your texts comply to the requirements of the Play Store, there is built-in a check that causes the build to fail if your texts exceed the allowed lengths.

The limits are:

  • Title: 30 characters
  • Short description: 80 characters
  • Long description: 4000 characters
  • Recent changes : 500 characters

To prevent this check from failing the build, you can toggle it with the errorOnSizeLimit property:

play {

  // ...
  errorOnSizeLimit = false 
}

Upload Images

To speed things up a little, images are only uploaded if you explicitly say so:

play {

  // ...
  uploadImages = true 
}

In that case the plugin looks for the Play Store images in your play folder. So just drop all your images into a folder structure similar to:

- [src]
|
+ - [main]

 |

 + - [play]

  |

  + - [en-US]

|

+ - [listing]

 |

 + - [featureGraphic]

 |

 + - [icon]

 |

 + - [phoneScreenshots]

 |

 + - [promoGraphic]

 |

 + - [sevenInchScreenshots]

 |

 + - [tenInchScreenshots]

 |

 + - [tvBanner]

 |

 + - [tvScreenshots]

 |

 + - [wearScreenshots] 

Note: The plugin does not enforce the correct size and file type. If you try to upload invalid files, the Google API will fail with a detailed error message.

Note: The plugin copies and merges the contents of the different play folders into a build folder for upload. If there are still images left from a previous build, this might lead to undesired behaviour. Please make sure to always do a ./gradlew clean whenever you rename or delete images in those directories.

Advanced Topics

Multiple service accounts

If you are developing for several customers you might run into a situation where each build flavor needs to be published into a separate Play Store Account. The plugin supports these use cases by defining separate playAccountConfigs and attach them to the flavors:

android {

  playAccountConfigs {

firstCustomerAccount {

 serviceAccountEmail = '[email protected]'

 pk12File = project.file('secret.pk12')

}

secondCustomerAccount {

 serviceAccountEmail = '[email protected]'

 pk12File = project.file('another-secret.pk12')

}

  
}

productFlavors {

firstCustomer {

 playAccountConfig = playAccountConfigs.firstCustomerAccount

}

secondCustomer {

 playAccountConfig = playAccountConfigs.secondCustomerAccount

}

  
}
 
}

Run custom tasks before publishing

Sometimes it's required to execute some custom tasks right before executing tasks from the play plugin.

For example, one can have necessity to download images for the store listing from a remote 3rd-party server. This should happen before executing the generateReleasePlayResources task which is responsible for collecting all the play store assets for upload.

Let's assume we have a task called loadStoreListingFromRemote that fetches store listing information from a remote server and places it under src/main/play as needed by the play plugin. Our generateReleasePlayResources task should now depend on that other task. In order to do that, we have to add the follwing lines to our build script:

project.afterEvaluate {

  def generateReleasePlayResources = project.tasks.getByName("generateReleasePlayResources")
  generateReleasePlayResources.dependsOn loadStoreListingFromRemote 
}

Note that we have to wait for the evaluation phase to complete before the generateReleasePlayResources task becomes visible.

Resources

Every major open-source project has its own style guide: a set of conventions (sometimes arbitrary) about how to write code for that project. It is much easier to understand a large codebase when all the code in it is in a consistent style.

"Style" covers a lot of ground, from "use camelCase for variable names" to "never use global variables" to "never use exceptions." This project holds the style guidelines we use for Google code. If you are modifying a project that originated at Google, you may be pointed to this page to see the style guides that apply to that project.

This library display hierarchical data (e.g. comments) in a list view, so that the user can collapse and expand elements. Every element is indented accordingly to its level in the hierarchy.

Floating Action Menu for Android. Inspired by the Google Plus floating menu.

PrettySharedPreferences is a lightweight library for help you deal with SharedPreferences more easy and reduce most of boilplace code.

Features:

  • Easy to use
  • Reduce a lot of boilerplate code

Switch Button with Material Design.

AKParallax-Android is a library project that provides a parallax effect to an ImageView in a ScrollView or a ListView.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes