diff options
author | Harsh Shandilya <msfjarvis@gmail.com> | 2020-11-15 14:04:14 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-15 09:34:14 +0100 |
commit | d3c1a73050cad74460a7fedddb114d196e5703aa (patch) | |
tree | ecd9ee3270a2c38e8d385e20d6a214ecde7466ef /buildSrc/src/main/java/BaseProjectConfig.kt | |
parent | 02c853c3b1124d8d37c357f7040abd579c51bf8a (diff) |
build: refactor for configuration cache compatibility (#1208)
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'buildSrc/src/main/java/BaseProjectConfig.kt')
-rw-r--r-- | buildSrc/src/main/java/BaseProjectConfig.kt | 42 |
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") |