aboutsummaryrefslogtreecommitdiff
path: root/buildSrc/src/main/java/BaseProjectConfig.kt
diff options
context:
space:
mode:
Diffstat (limited to 'buildSrc/src/main/java/BaseProjectConfig.kt')
-rw-r--r--buildSrc/src/main/java/BaseProjectConfig.kt42
1 files changed, 42 insertions, 0 deletions
diff --git a/buildSrc/src/main/java/BaseProjectConfig.kt b/buildSrc/src/main/java/BaseProjectConfig.kt
index e1d53dd8..2a7b81d9 100644
--- a/buildSrc/src/main/java/BaseProjectConfig.kt
+++ b/buildSrc/src/main/java/BaseProjectConfig.kt
@@ -9,6 +9,7 @@ import org.gradle.api.Project
import org.gradle.api.tasks.Delete
import org.gradle.api.tasks.testing.Test
import org.gradle.api.tasks.testing.logging.TestLogEvent
+import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
import org.gradle.api.tasks.wrapper.Wrapper
import org.gradle.kotlin.dsl.repositories
import org.gradle.kotlin.dsl.withType
@@ -56,6 +57,47 @@ internal fun Project.configureForAllProjects() {
}
/**
+ * Checks if we're building a snapshot
+ */
+@Suppress("UnstableApiUsage")
+fun Project.isSnapshot(): Boolean {
+ with(project.providers) {
+ val workflow = environmentVariable("GITHUB_WORKFLOW").forUseAtConfigurationTime()
+ val snapshot = environmentVariable("SNAPSHOT").forUseAtConfigurationTime()
+ return workflow.isPresent && snapshot.isPresent
+ }
+}
+
+/**
+ * Apply configurations for app module
+ */
+@Suppress("UnstableApiUsage")
+internal fun BaseAppModuleExtension.configureAndroidApplicationOptions(project: Project) {
+ val minifySwitch = project.providers.environmentVariable("DISABLE_MINIFY").forUseAtConfigurationTime()
+
+ adbOptions.installOptions("--user 0")
+
+ buildFeatures {
+ viewBinding = true
+ buildConfig = true
+ }
+
+ buildTypes {
+ named("release") {
+ isMinifyEnabled = !minifySwitch.isPresent
+ setProguardFiles(listOf("proguard-android-optimize.txt", "proguard-rules.pro"))
+ buildConfigField("boolean", "ENABLE_DEBUG_FEATURES", "${project.isSnapshot()}")
+ }
+ named("debug") {
+ applicationIdSuffix = ".debug"
+ versionNameSuffix = "-debug"
+ isMinifyEnabled = false
+ buildConfigField("boolean", "ENABLE_DEBUG_FEATURES", "true")
+ }
+ }
+}
+
+/**
* Apply baseline configurations for all Android projects (Application and Library).
*/
@Suppress("UnstableApiUsage")