diff options
author | cyberta <cyberta@riseup.net> | 2018-06-24 15:17:53 -0700 |
---|---|---|
committer | cyberta <cyberta@riseup.net> | 2018-06-24 15:17:53 -0700 |
commit | ee64bde0da3ef44387e8af7ef980c4b1bb63565c (patch) | |
tree | 021e30145e45726b276f1b7b4dbae3d95109bb28 /app/build.gradle | |
parent | 55c3972e9ac0796a801c64788eb364cbd0c9cf02 (diff) | |
parent | ea4c5ca2b27aeabd4a1b000ac2066be6023b2e45 (diff) |
Merge branch 'customisation_feature' into 'master'
Customisation feature
See merge request leap/bitmask_android!75
Diffstat (limited to 'app/build.gradle')
-rw-r--r-- | app/build.gradle | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/app/build.gradle b/app/build.gradle index 09858cd2..e8f8b78f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,7 +1,9 @@ +import java.util.concurrent.ExecutionException import java.util.regex.Matcher import java.util.regex.Pattern apply plugin: 'com.android.application' +def appName = '' android { compileSdkVersion 27 @@ -42,7 +44,7 @@ android { } } - flavorDimensions "implementation" + flavorDimensions "mode","implementation" productFlavors { production { dimension "implementation" @@ -50,6 +52,34 @@ android { insecure { dimension "implementation" } + normal { + dimension "mode" + } + //Configurations for custom branded app. + custom { + dimension "mode" + //Change the package name as needed + applicationId "org.sample.custom" + //Set app name here + appName = "Custom" + resValue "string", "app_name", appName + //Change the versionCode as needed + versionCode 1 + //Change the versionName as needed + versionName "1.0" + + //Build Config Fields for default donation details + + //This is the donation URL and should be set to the relevant donation page. + buildConfigField 'String', 'donation_url', '"https://leap.se/en/about-us/donate"' + //The field to enable donations in the app. + buildConfigField 'boolean', 'enable_donation', 'true' + //The field to enable donation reminder popup in the app if enable_donation is set to 'false' this will be disabled. + buildConfigField 'boolean', 'enable_donation_reminder', 'true' + //The duration in days to trigger the donation reminder + buildConfigField 'int', 'donation_reminder_duration', '30' + + } } buildTypes { @@ -340,3 +370,41 @@ def getCurrentFlavorForBetaOrRelease() { return ""; } } + +def getCurrentFlavor() { + Gradle gradle = getGradle() + String tskReqStr = gradle.getStartParameter().getTaskRequests().toString() + + Pattern pattern; + + if (tskReqStr.contains("assemble")) + pattern = Pattern.compile("assemble(\\w+)(Beta|Release|Debug)") + else + pattern = Pattern.compile("generate(\\w+)(Beta|Release|Debug)") + + Matcher matcher = pattern.matcher(tskReqStr) + + if (matcher.find()) + return matcher.group(1).toLowerCase() + else { + return ""; + } +} + +task checkApplicationIdForCustomFlavor(type: Exec) { + def currFlavor = getCurrentFlavor() + if (currFlavor.contains("custom")) { + android.applicationVariants.all { variant -> + def mergedFlavor = variant.mergedFlavor + if (variant.flavorName.toString().equalsIgnoreCase(currFlavor) && + mergedFlavor.getApplicationId().equalsIgnoreCase("org.sample.custom")) + throw new ExecutionException("ERROR: please change the applicationId(org.sample.custom) if you want to build a custom branded app!") + } + } +} + +task checkAppNameForCustomFlavor(type: Exec) { + def currFlavor = getCurrentFlavor() + if (currFlavor.contains("custom") && appName.equalsIgnoreCase("custom")) + throw new ExecutionException("ERROR: please change the appName(Custom) if you want to build a custom branded app!") +}
\ No newline at end of file |