I need to write a gradle script to auto version my application on every commit. I need to also include the commit hash as a reference in the application for testers.
add following code to your build.gradle
def gitCommitHash = 'git rev-parse --verify --short HEAD'.execute().text.trim()
defaultConfig{ ... otherConfigs buildConfigField("String", "GIT_HASH", "\"${gitCommitHash}\"") }
now you can get git hash by BuildConfig.GIT_HASH
BuildConfig.GIT_HASH
have fun