Last Updated: February 25, 2016
·
1.035K
· carlosefonseca

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()
}

1 Response
Add your response