Created
September 30, 2015 09:43
-
-
Save dominicthomas/06124c874d5ccc5ca0c1 to your computer and use it in GitHub Desktop.
Simple way of incrementing the app versionCode when a particular task is run. Useful to increment versionCode when doing a production release build.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Increment version code when running a production release | |
def versionPropsFile = file('version.properties') | |
if (versionPropsFile.canRead()) { | |
def Properties versionProps = new Properties() | |
versionProps.load(new FileInputStream(versionPropsFile)) | |
def value = 0 | |
def runTasks = gradle.startParameter.taskNames | |
if ('assembleProductionRelease' in runTasks) { | |
value = 1; | |
} | |
def version_Code = versionProps['VERSION_CODE'].toInteger() + value | |
versionProps['VERSION_CODE'] = version_Code.toString() | |
versionProps.store(versionPropsFile.newWriter(), null) | |
defaultConfig { | |
versionCode version_Code | |
} | |
} else { | |
throw new GradleException("Could not read version.properties!") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment