w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to create an Android Studio build script to insert git commit hash in build version?

From this post by Ryan Harter, tag your commit and add the following to your build.gradle script.

 * Gets the version name from the latest Git tag
def getVersionName = { ->
    def stdout = new ByteArrayOutputStream()
    exec {
        commandLine 'git', 'describe', '--tags'
        standardOutput = stdout
    return stdout.toString().trim()

Then change the versionName in defaultConfig to use getVersionName().

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.