I'm looking for a way to include the git branch name into my android apk file name upon building it.
I would like to name my apk file "ProjectName-git branchname.apk, automatically upon building it. "
Example: "MyTestProject-master.apk"
I've searched online and read the gradle docs but can't find a reference to how to include the branch name into the output file name.
I know how to use gradle to construct a file name, generally speaking. I'm specifically asking about the git branch reference.
since you know how to use Gradle to construct a file name,
Here is the task to fetch current git branch name into your Gradle...
def getBranchName = { ->
try {
println "Task Getting Branch Name.."
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--abbrev-ref', 'HEAD'
standardOutput = stdout
}
println "Git Current Branch = " + stdout.toString()
return stdout.toString()
}
catch (Exception e) {
println "Exception = " + e.getMessage()
return null;
}
}
You can concatenate it with your file name.
Hope it helps..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With