diff options
Diffstat (limited to 'buildSrc')
-rw-r--r-- | buildSrc/src/main/java/BaseProjectConfig.kt | 42 | ||||
-rw-r--r-- | buildSrc/src/main/java/PasswordStorePlugin.kt | 7 | ||||
-rw-r--r-- | buildSrc/src/main/java/SigningConfig.kt | 34 |
3 files changed, 82 insertions, 1 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") diff --git a/buildSrc/src/main/java/PasswordStorePlugin.kt b/buildSrc/src/main/java/PasswordStorePlugin.kt index 37a23b02..b8271f65 100644 --- a/buildSrc/src/main/java/PasswordStorePlugin.kt +++ b/buildSrc/src/main/java/PasswordStorePlugin.kt @@ -4,6 +4,7 @@ */ import com.android.build.gradle.TestedExtension +import com.android.build.gradle.internal.dsl.BaseAppModuleExtension import com.android.build.gradle.internal.plugins.AppPlugin import com.android.build.gradle.internal.plugins.LibraryPlugin import org.gradle.api.Plugin @@ -32,8 +33,12 @@ class PasswordStorePlugin : Plugin<Project> { options.isDeprecation = true } } - is LibraryPlugin, + is LibraryPlugin -> { + project.extensions.getByType<TestedExtension>().configureCommonAndroidOptions() + } is AppPlugin -> { + project.extensions.getByType<BaseAppModuleExtension>().configureAndroidApplicationOptions(project) + project.extensions.getByType<BaseAppModuleExtension>().configureBuildSigning(project) project.extensions.getByType<TestedExtension>().configureCommonAndroidOptions() } } diff --git a/buildSrc/src/main/java/SigningConfig.kt b/buildSrc/src/main/java/SigningConfig.kt new file mode 100644 index 00000000..1f494d5f --- /dev/null +++ b/buildSrc/src/main/java/SigningConfig.kt @@ -0,0 +1,34 @@ +/* + * Copyright © 2014-2020 The Android Password Store Authors. All Rights Reserved. + * SPDX-License-Identifier: GPL-3.0-only + */ + +import com.android.build.gradle.internal.dsl.BaseAppModuleExtension +import java.util.Properties +import org.gradle.api.Project + +private const val KEYSTORE_CONFIG_PATH = "keystore.properties" + +/** + * Configure signing for all build types. + */ +@Suppress("UnstableApiUsage") +internal fun BaseAppModuleExtension.configureBuildSigning(project: Project) { + with(project) { + val keystoreConfigFile = rootProject.layout.projectDirectory.file(KEYSTORE_CONFIG_PATH) + if (!keystoreConfigFile.asFile.exists()) return + val contents = providers.fileContents(keystoreConfigFile).asText.forUseAtConfigurationTime() + val keystoreProperties = Properties() + keystoreProperties.load(contents.get().byteInputStream()) + signingConfigs { + register("release") { + keyAlias = keystoreProperties["keyAlias"] as String + keyPassword = keystoreProperties["keyPassword"] as String + storeFile = rootProject.file(keystoreProperties["storeFile"] as String) + storePassword = keystoreProperties["storePassword"] as String + } + } + val signingConfig = signingConfigs.getByName("release") + buildTypes.all { setSigningConfig(signingConfig) } + } +} |