From a3bce7f7caf14f034fd550870bcbeaf5d04dee5e Mon Sep 17 00:00:00 2001 From: Stypox Date: Sun, 23 Feb 2020 09:46:42 +0100 Subject: [PATCH 1/3] Change app id based on current git branch This enables to install multiple builds from different branches at once --- app/build.gradle | 11 ++++++++++- app/src/debug/AndroidManifest.xml | 17 ----------------- app/src/main/res/values/strings.xml | 1 - 3 files changed, 10 insertions(+), 19 deletions(-) delete mode 100644 app/src/debug/AndroidManifest.xml diff --git a/app/build.gradle b/app/build.gradle index c2bceab9e..36a712cc3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,6 +9,7 @@ android { defaultConfig { applicationId "org.schabi.newpipe" + resValue "string", "app_name", "NewPipe" minSdkVersion 19 targetSdkVersion 28 versionCode 840 @@ -28,7 +29,15 @@ android { debug { multiDexEnabled true debuggable true - applicationIdSuffix ".debug" + + def workingBranch = "git rev-parse --abbrev-ref HEAD".execute().text.trim() + if (workingBranch.isEmpty() || workingBranch == "master" || workingBranch == "dev") { + applicationIdSuffix ".debug" + resValue "string", "app_name", "NewPipe Debug" + } else { + applicationIdSuffix ".debug." + workingBranch.replaceAll("[^A-Za-z]+", "") + resValue "string", "app_name", "NewPipe " + workingBranch + } } } diff --git a/app/src/debug/AndroidManifest.xml b/app/src/debug/AndroidManifest.xml deleted file mode 100644 index a16d6796a..000000000 --- a/app/src/debug/AndroidManifest.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 148a339a9..bcbfcd6d0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,6 +1,5 @@ - NewPipe Tap \"Search\" to get started %1$s views Published on %1$s From 030e5ab894ed576e9e63332c6b08cdda090eade6 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sun, 23 Feb 2020 20:56:56 +0100 Subject: [PATCH 2/3] Add comment to gradle --- app/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/app/build.gradle b/app/build.gradle index 36a712cc3..2329a7a0e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -30,6 +30,7 @@ android { multiDexEnabled true 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") { applicationIdSuffix ".debug" From 92f4010e8ee16f0ebebad91e9d217fa20e2e0418 Mon Sep 17 00:00:00 2001 From: Stypox Date: Mon, 2 Mar 2020 20:50:35 +0100 Subject: [PATCH 3/3] Add more checks to prevent build failures in gradle branch suffix - Add function `getGitWorkingBranch` that returns the current working branch, and "" if it could not be determined (either because git is not installed or because the directory is not a git repo). - Make sure normalizedWorkingBranch is not empty (leading to an invalid app id terminating with `.`) - Make normalizedWorkingBranch lowercase - Add comments --- app/build.gradle | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) 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 } }