build-logic: add android convention plugins
This commit is contained in:
parent
553a9e8492
commit
dfee170bd8
6 changed files with 183 additions and 1 deletions
|
@ -1,3 +1,11 @@
|
|||
plugins { `kotlin-dsl` }
|
||||
/*
|
||||
* Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
|
||||
plugins {
|
||||
`kotlin-dsl`
|
||||
`kotlin-dsl-precompiled-script-plugins`
|
||||
}
|
||||
|
||||
dependencies { implementation(libs.build.agp) }
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
|
||||
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
|
||||
import flavors.FlavorDimensions
|
||||
import flavors.ProductFlavors
|
||||
import flavors.configureSlimTests
|
||||
import org.gradle.kotlin.dsl.configure
|
||||
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
id("com.github.android-password-store.android-common")
|
||||
}
|
||||
|
||||
fun Project.isSnapshot(): Boolean {
|
||||
with(project.providers) {
|
||||
val workflow = environmentVariable("GITHUB_WORKFLOW").forUseAtConfigurationTime()
|
||||
val snapshot = environmentVariable("SNAPSHOT").forUseAtConfigurationTime()
|
||||
return workflow.isPresent || snapshot.isPresent
|
||||
}
|
||||
}
|
||||
|
||||
extensions.configure<BaseAppModuleExtension> {
|
||||
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",
|
||||
"proguard-rules-missing-classes.pro",
|
||||
)
|
||||
)
|
||||
buildConfigField("boolean", "ENABLE_DEBUG_FEATURES", "${project.isSnapshot()}")
|
||||
}
|
||||
named("debug") {
|
||||
applicationIdSuffix = ".debug"
|
||||
versionNameSuffix = "-debug"
|
||||
isMinifyEnabled = false
|
||||
buildConfigField("boolean", "ENABLE_DEBUG_FEATURES", "true")
|
||||
}
|
||||
}
|
||||
|
||||
flavorDimensions.add(FlavorDimensions.FREE)
|
||||
productFlavors {
|
||||
register(ProductFlavors.FREE) {}
|
||||
register(ProductFlavors.NON_FREE) {}
|
||||
}
|
||||
|
||||
project.configureSlimTests()
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
|
||||
import com.android.build.gradle.TestedExtension
|
||||
|
||||
extensions.configure<TestedExtension> {
|
||||
setCompileSdkVersion(31)
|
||||
defaultConfig {
|
||||
minSdk = 23
|
||||
targetSdk = 29
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
named("main") { java.srcDirs("src/main/kotlin") }
|
||||
named("test") { java.srcDirs("src/test/kotlin") }
|
||||
named("androidTest") { java.srcDirs("src/androidTest/kotlin") }
|
||||
}
|
||||
|
||||
packagingOptions {
|
||||
resources.excludes.add("**/*.version")
|
||||
resources.excludes.add("**/*.txt")
|
||||
resources.excludes.add("**/*.kotlin_module")
|
||||
resources.excludes.add("**/plugin.properties")
|
||||
resources.excludes.add("**/META-INF/AL2.0")
|
||||
resources.excludes.add("**/META-INF/LGPL2.1")
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
}
|
||||
|
||||
testOptions {
|
||||
animationsDisabled = true
|
||||
unitTests.isReturnDefaultValues = true
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
* Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
|
||||
import flavors.configureSlimTests
|
||||
|
||||
plugins {
|
||||
id("com.android.library")
|
||||
id("com.github.android-password-store.android-common")
|
||||
}
|
||||
|
||||
project.configureSlimTests()
|
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
|
||||
package flavors
|
||||
|
||||
object FlavorDimensions {
|
||||
const val FREE = "free"
|
||||
}
|
||||
|
||||
object ProductFlavors {
|
||||
const val FREE = "free"
|
||||
const val NON_FREE = "nonFree"
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
|
||||
package flavors
|
||||
|
||||
import com.android.build.api.variant.ApplicationAndroidComponentsExtension
|
||||
import com.android.build.api.variant.LibraryAndroidComponentsExtension
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.findByType
|
||||
import org.gradle.language.nativeplatform.internal.BuildType
|
||||
|
||||
/**
|
||||
* When the "slimTests" project property is provided, disable the unit test tasks on `release` build
|
||||
* type and `nonFree` product flavor to avoid running the same tests repeatedly in different build
|
||||
* variants.
|
||||
*
|
||||
* Examples: `./gradlew test -PslimTests` will run unit tests for `nonFreeDebug` and `debug` build
|
||||
* variants in Android App and Library projects, and all tests in JVM projects.
|
||||
*/
|
||||
internal fun Project.configureSlimTests() {
|
||||
if (providers.gradleProperty(SLIM_TESTS_PROPERTY).forUseAtConfigurationTime().isPresent) {
|
||||
// disable unit test tasks on the release build type for Android Library projects
|
||||
extensions.findByType<LibraryAndroidComponentsExtension>()?.run {
|
||||
beforeVariants(selector().withBuildType(BuildType.RELEASE.name)) {
|
||||
it.enableUnitTest = false
|
||||
it.enableAndroidTest = false
|
||||
}
|
||||
}
|
||||
|
||||
// disable unit test tasks on the release build type and free flavor for Android Application
|
||||
// projects.
|
||||
extensions.findByType<ApplicationAndroidComponentsExtension>()?.run {
|
||||
beforeVariants(selector().withBuildType(BuildType.RELEASE.name)) { it.enableUnitTest = false }
|
||||
beforeVariants(selector().withFlavor(FlavorDimensions.FREE to ProductFlavors.NON_FREE)) {
|
||||
it.enableUnitTest = false
|
||||
it.enableAndroidTest = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private const val SLIM_TESTS_PROPERTY = "slimTests"
|
Loading…
Reference in a new issue