Created
November 15, 2016 16:45
-
-
Save kamiranoff/0ed2eeb9b46a66e9a8dc9763e2c16c71 to your computer and use it in GitHub Desktop.
increment android build version
This file contains 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
def readVersion() { | |
def versionFile = new File(project.rootDir, 'version.properties') | |
def version = new Properties() | |
def stream | |
try { | |
stream = new FileInputStream(versionFile) | |
version.load(stream) | |
}catch (FileNotFoundException ignore) { | |
}finally { | |
if(stream != null) stream.close() | |
} | |
//safety defaults in case file is missing | |
if(!version['major']) version['major'] = "1" | |
if(!version['minor']) version['minor'] = "0" | |
if(!version['build']) version['build'] = "0" | |
return version | |
} | |
def readVersionName() { | |
def version = readVersion() | |
return "${version['major']}.${version['minor']}" | |
} | |
def readBuildCode() { | |
def version = readVersion() | |
def build = version['build'] as int | |
return build | |
} | |
def incrementBuildNumber() { | |
def versionFile = new File.read(project.rootDir, 'version.properties') | |
def version = readVersion() | |
def build = version['build'] as int | |
build++ | |
version['build'] = build.toString() | |
def stream = new FileOutputStream(versionFile) | |
try { | |
version.store(stream, null) | |
}finally { | |
stream.close() | |
} | |
print "Build number is now ..." + build | |
return build | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment