Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # First create the file version.properties with value VERSION_BUILD=0
- # In app/build.gradle:
- android {
- def versionPropsFile = file('version.properties')
- def versionBuild
- if (versionPropsFile.canRead()) {
- def Properties versionProps = new Properties()
- versionProps.load(new FileInputStream(versionPropsFile))
- versionBuild = versionProps['VERSION_BUILD'].toInteger()
- } else {
- throw new FileNotFoundException("Could not read version.properties!")
- }
- ext.autoIncrementBuildNumber = {
- if (versionPropsFile.canRead()) {
- def Properties versionProps = new Properties()
- versionProps.load(new FileInputStream(versionPropsFile))
- versionBuild = versionProps['VERSION_BUILD'].toInteger() + 1
- versionProps['VERSION_BUILD'] = versionBuild.toString()
- versionProps.store(versionPropsFile.newWriter(), null)
- } else {
- throw new FileNotFoundException("Could not read version.properties!")
- }
- }
- # Add / change this part in defaultConfig for the versionCode
- defaultConfig {
- versionCode versionBuild
- }
- gradle.taskGraph.whenReady { taskGraph ->
- if (taskGraph.hasTask(assembleDebug)) {
- autoIncrementBuildNumber()
- } else if (taskGraph.hasTask(assembleRelease)) {
- autoIncrementBuildNumber()
- }
- }
- }
Add Comment
Please, Sign In to add comment