Adding git revision code to Android
This gets the current git revision as a variable on the BuildConfig file. I'm sending it to Crashlytics as a piece of data so I can figure out easily what commit does that stack trace relates to.
android {
buildTypes {
debug {
buildConfigField "String", "GIT", "\"${gitRevision()}\""
}
release {
buildConfigField "String", "GIT", "\"${gitRevision()}\""
}
}
}
def gitRevision() {
def cmd = "git rev-parse --short HEAD"
return cmd.execute().text.trim()
}
Written by Carlos Fonseca
Related protips
1 Response
Sources that helped me get here:
http://forums.gradle.org/gradle/topics/how_can_i_store_the_git_revision_for_use_in_the_project and
http://stackoverflow.com/questions/17197636/is-it-possible-to-declare-a-variable-in-gradle-usable-in-java
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Android
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#