Skip to content

Instantly share code, notes, and snippets.

@nsmirosh
Created August 1, 2025 16:17
Show Gist options
  • Select an option

  • Save nsmirosh/5ec7aa47289063023cd0af06fdee0c47 to your computer and use it in GitHub Desktop.

Select an option

Save nsmirosh/5ec7aa47289063023cd0af06fdee0c47 to your computer and use it in GitHub Desktop.
Auto-increment build version
android {
val versionPropsFile = file("../version.properties")
if (versionPropsFile.canRead()) {
val versionProps = Properties()
versionProps.load(FileInputStream(versionPropsFile))
val code = versionProps["VERSION_CODE"].toString().toInt() + 1
versionProps["VERSION_CODE"] = code.toString()
versionProps.store(versionPropsFile.writer(), null)
defaultConfig {
versionCode = code
}
} else {
throw GradleException("Could not read version.properties!")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment