|
|
|
@ -1,13 +1,28 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2025 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package com.google.samples.apps.nowinandroid
|
|
|
|
|
|
|
|
|
|
import com.android.build.api.dsl.ApplicationExtension
|
|
|
|
|
import com.android.build.api.dsl.ApplicationProductFlavor
|
|
|
|
|
import com.android.build.api.dsl.CommonExtension
|
|
|
|
|
import com.android.build.api.dsl.ProductFlavor
|
|
|
|
|
|
|
|
|
|
@Suppress("EnumEntryName")
|
|
|
|
|
enum class FlavorDimension {
|
|
|
|
|
contentType
|
|
|
|
|
contentType,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The content for the app can either come from local static data which is useful for demo
|
|
|
|
@ -23,7 +38,21 @@ fun configureFlavors(
|
|
|
|
|
commonExtension: CommonExtension<*, *, *, *, *, *>,
|
|
|
|
|
flavorConfigurationBlock: ProductFlavor.(flavor: NiaFlavor) -> Unit = {},
|
|
|
|
|
) {
|
|
|
|
|
commonExtension.apply {
|
|
|
|
|
when (commonExtension) {
|
|
|
|
|
is ApplicationExtension -> commonExtension.configureFlavors { nia ->
|
|
|
|
|
flavorConfigurationBlock(this, nia)
|
|
|
|
|
this.applicationIdSuffix = nia.applicationIdSuffix
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else -> commonExtension.configureFlavors(flavorConfigurationBlock)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JvmName("configureFlavorsImpl")
|
|
|
|
|
private inline fun <E : CommonExtension<*, *, *, out F, *, *>, F : ProductFlavor> E.configureFlavors(
|
|
|
|
|
crossinline flavorConfigurationBlock: F.(flavor: NiaFlavor) -> Unit = {},
|
|
|
|
|
) {
|
|
|
|
|
apply {
|
|
|
|
|
FlavorDimension.values().forEach { flavorDimension ->
|
|
|
|
|
flavorDimensions += flavorDimension.name
|
|
|
|
|
}
|
|
|
|
@ -33,11 +62,6 @@ fun configureFlavors(
|
|
|
|
|
register(niaFlavor.name) {
|
|
|
|
|
dimension = niaFlavor.dimension.name
|
|
|
|
|
flavorConfigurationBlock(this, niaFlavor)
|
|
|
|
|
if (this@apply is ApplicationExtension && this is ApplicationProductFlavor) {
|
|
|
|
|
if (niaFlavor.applicationIdSuffix != null) {
|
|
|
|
|
applicationIdSuffix = niaFlavor.applicationIdSuffix
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|