An Android-Gradle plugin to set the build version based on the last APK uploaded on PlayStore
On your build.gradle
add:
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/' }
}
dependencies {
classpath 'gradle.plugin.gmazzo:play-autoincrement-plugin:+'
}
}
apply plugin: 'com.github.gmazzo.play-autoincrement'
Visit Gradle plugins for further details on how to apply it
The plugin creates one task per `build-variant. In a simple Android project you will have:
computeNextDebugVersion
computeNextReleaseVersion
Be aware of those tasks will run in a very early step on your Gradle build (between preReleaseBuild
and checkReleaseManifest
tasks).
If your Gradle Sync fails on Android Studio (due an Internet unavailability for example), see the section Fail on errors
On your build.gradle
add:
autoincrement {
jsonFile '<path-to-google-api-json-token>'
}
If you have configured the gradle-play-publisher (or going to), then you don't need to add the autoincrement
closure the Gradle script. Just apply the plugin that it will pick the configurtion from Triple-T's play
closure.
This plugin supports low-level GoogleCredentials API by providing an InputStream with the JSON API Key content:
autoincrement {
jsonStream 'http://myserver/google-api-key.json'.toURL().openStream()
}
By default, the plugin will only target any non-debuggable build variant.
You can customize this behaviour with the targetVariants
closure.
For example, an hypothetical flavor1Release
variant only do:
autoincrement {
targetVariants { variant -> variant.name == 'flavor1Release' }
}
autoincrement {
codeFormatter { code, variant -> code + 1 }
}
Set it to null
for leave the versionCode untouched
autoincrement {
nameFormatter { code, variant -> "${variant.versionName}.$code-${new Date().format('yyyyMMdd-HHmmss')}" }
}
Set it to null
for leave the versionName untouched
By default, the plugin will fail on any error and leave the version untouched. You can change this by setting:
autoincrement {
failOnErrors false
}