Last active
May 18, 2018 07:06
-
-
Save bobvanderlinden/c1604c8fcdd15d08d197b252a8545351 to your computer and use it in GitHub Desktop.
Git revision in Android build config using Gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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