diff --git a/app/build.gradle b/app/build.gradle index 2329a7a0e..61929173e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,6 +3,24 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' + +static String getGitWorkingBranch() { + try { + def gitProcess = "git rev-parse --abbrev-ref HEAD".execute() + gitProcess.waitFor() + if (gitProcess.exitValue() == 0) { + return gitProcess.text.trim() + } else { + // not a git repository + return "" + } + } catch (IOException ignored) { + // git was not found + return "" + } +} + + android { compileSdkVersion 28 buildToolsVersion '28.0.3' @@ -31,12 +49,14 @@ android { debuggable true // suffix the app id and the app name with git branch name - def workingBranch = "git rev-parse --abbrev-ref HEAD".execute().text.trim() - if (workingBranch.isEmpty() || workingBranch == "master" || workingBranch == "dev") { + def workingBranch = getGitWorkingBranch() + def normalizedWorkingBranch = workingBranch.replaceAll("[^A-Za-z]+", "").toLowerCase() + if (normalizedWorkingBranch.isEmpty() || workingBranch == "master" || workingBranch == "dev") { + // default values when branch name could not be determined or is master or dev applicationIdSuffix ".debug" resValue "string", "app_name", "NewPipe Debug" } else { - applicationIdSuffix ".debug." + workingBranch.replaceAll("[^A-Za-z]+", "") + applicationIdSuffix ".debug." + normalizedWorkingBranch resValue "string", "app_name", "NewPipe " + workingBranch } }