Skip to content

Instantly share code, notes, and snippets.

@bobvanderlinden
Last active May 18, 2018 07:06
Show Gist options
  • Select an option

  • Save bobvanderlinden/c1604c8fcdd15d08d197b252a8545351 to your computer and use it in GitHub Desktop.

Select an option

Save bobvanderlinden/c1604c8fcdd15d08d197b252a8545351 to your computer and use it in GitHub Desktop.
Git revision in Android build config using Gradle
def exec(String cmdline) {
def os = new ByteArrayOutputStream()
exec {
commandLine cmdline.split(" ")
standardOutput = os;
}
return os.toString().replaceAll('\\s', '')
}
def getGitSha() {
return exec('git rev-parse --short HEAD')
}
android {
buildTypes {
debug {
# Make sure debug builds aren't being rebuild each time you do a commit.
buildConfigField "String", "GIT_SHA", "\"\""
}
release {
buildConfigField "String", "GIT_SHA", "\"" + getGitSha() + "\""
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment