From 65d7e4519ea75826d76c0e79fcc11fa586718430 Mon Sep 17 00:00:00 2001 From: Jaehwa Noh Date: Sat, 6 Jul 2024 20:18:38 +0900 Subject: [PATCH 1/2] Refactor to improve `FlavorDimension` extensibility, and replace to `register` lazy api. Change-Id: I6e2980f19da5a6e22a7773c84493424663e33fc4 --- .../com/google/samples/apps/nowinandroid/NiaFlavor.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/NiaFlavor.kt b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/NiaFlavor.kt index 633098604..c3d996014 100644 --- a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/NiaFlavor.kt +++ b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/NiaFlavor.kt @@ -21,13 +21,16 @@ enum class NiaFlavor(val dimension: FlavorDimension, val applicationIdSuffix: St fun configureFlavors( commonExtension: CommonExtension<*, *, *, *, *, *>, - flavorConfigurationBlock: ProductFlavor.(flavor: NiaFlavor) -> Unit = {} + flavorConfigurationBlock: ProductFlavor.(flavor: NiaFlavor) -> Unit = {}, ) { commonExtension.apply { - flavorDimensions += FlavorDimension.contentType.name + FlavorDimension.values().forEach { + flavorDimensions += it.name + } + productFlavors { NiaFlavor.values().forEach { - create(it.name) { + register(it.name) { dimension = it.dimension.name flavorConfigurationBlock(this, it) if (this@apply is ApplicationExtension && this is ApplicationProductFlavor) { From ba5edc5014a6160bc6bb051670d7e04f2d6f9b36 Mon Sep 17 00:00:00 2001 From: Jaehwa Noh Date: Sun, 7 Jul 2024 09:07:42 +0900 Subject: [PATCH 2/2] Add explicit variable name in lambda based on Type name. Change-Id: Ife739bcebb9b2586a6045ddac241f1591927c4b6 --- .../samples/apps/nowinandroid/NiaFlavor.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/NiaFlavor.kt b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/NiaFlavor.kt index c3d996014..f57e634cc 100644 --- a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/NiaFlavor.kt +++ b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/NiaFlavor.kt @@ -16,7 +16,7 @@ enum class FlavorDimension { @Suppress("EnumEntryName") enum class NiaFlavor(val dimension: FlavorDimension, val applicationIdSuffix: String? = null) { demo(FlavorDimension.contentType, applicationIdSuffix = ".demo"), - prod(FlavorDimension.contentType) + prod(FlavorDimension.contentType), } fun configureFlavors( @@ -24,18 +24,18 @@ fun configureFlavors( flavorConfigurationBlock: ProductFlavor.(flavor: NiaFlavor) -> Unit = {}, ) { commonExtension.apply { - FlavorDimension.values().forEach { - flavorDimensions += it.name + FlavorDimension.values().forEach { flavorDimension -> + flavorDimensions += flavorDimension.name } productFlavors { - NiaFlavor.values().forEach { - register(it.name) { - dimension = it.dimension.name - flavorConfigurationBlock(this, it) + NiaFlavor.values().forEach { niaFlavor -> + register(niaFlavor.name) { + dimension = niaFlavor.dimension.name + flavorConfigurationBlock(this, niaFlavor) if (this@apply is ApplicationExtension && this is ApplicationProductFlavor) { - if (it.applicationIdSuffix != null) { - applicationIdSuffix = it.applicationIdSuffix + if (niaFlavor.applicationIdSuffix != null) { + applicationIdSuffix = niaFlavor.applicationIdSuffix } } }