Fixed getting git hash in new Android Studio

This commit is contained in:
ByteHamster 2021-04-17 17:17:11 +02:00
parent 068e163dd7
commit e6aa8831f1
1 changed files with 8 additions and 3 deletions

View File

@ -31,12 +31,17 @@ android {
testApplicationId "de.test.antennapod" testApplicationId "de.test.antennapod"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
def commit = "Unknown commit" def commit = ""
try { try {
commit = "git rev-parse --short HEAD".execute().text.trim() def hashStdOut = new ByteArrayOutputStream()
exec {
commandLine "git", "rev-parse", "--short", "HEAD"
standardOutput = hashStdOut
}
commit = hashStdOut.toString().trim()
} catch (Exception ignore) { } catch (Exception ignore) {
} }
buildConfigField "String", "COMMIT_HASH", ('"' + commit + '"') buildConfigField "String", "COMMIT_HASH", ('"' + (commit.isEmpty() ? "Unknown commit" : commit) + '"')
if (project.hasProperty("podcastindexApiKey")) { if (project.hasProperty("podcastindexApiKey")) {
buildConfigField "String", "PODCASTINDEX_API_KEY", '"' + podcastindexApiKey + '"' buildConfigField "String", "PODCASTINDEX_API_KEY", '"' + podcastindexApiKey + '"'