Anyone know how to create a flavor config using gr...
# android
m
Anyone know how to create a flavor config using gradle.kts? I've found this medium articled(link below) that does something similar but it isn's in .kts...https://medium.com/stepstone-tech/modularizing-your-flavored-android-project-5db75c59fb0d
m
Copy code
productFlavors {
        create("bedcon") {
            flavorDimensions("sessionize")
            applicationIdSuffix = ".bedcon"            
        }
        create("apachecon") {
            flavorDimensions("sessionize")
            applicationIdSuffix = ".apachecon"
        }
https://github.com/dukecon/dukecon_mobile/blob/feature/diy-DI/frontend/android/build.gradle.kts
the app also uses different dependencies for different flavours
m
Copy code
ext.flavorConfig = { // 1

    flavorDimensions "pricing"
    productFlavors {
        free {
            dimension "pricing"
            ext.myApplicationIdSuffix = '.free' // 2
        }
        paid {
            dimension "pricing"
            ext.myApplicationIdSuffix = '.paid'
        }
    }

    productFlavors.all { flavor -> // 3
        if (flavor.hasProperty('myApplicationIdSuffix') && isApplicationProject()) {
            flavor.applicationIdSuffix = flavor.myApplicationIdSuffix
        }
    }

}

def isApplicationProject() { // 4
    return project.android.class.simpleName.startsWith('BaseAppModuleExtension')
    // in AGP 3.1.x with library modules instead of feature modules:
    // return project.android instanceof com.android.build.gradle.AppExtension
}
The problem im finding is creating a separate config file (flavor.config) to eliminate the boilerplate code for each module. The article's solution does that and uses the groovy method "with", but atm I cant find the kts equivalent
m
I don't have finished code for that, but I've probably put it as gradle extention into `buildSrc`like this https://github.com/dukecon/dukecon_mobile/blob/feature/diy-DI/buildSrc/src/main/kotlin/AndroidLibraryExtention.kt then you can call it like a function, like here https://github.com/dukecon/dukecon_mobile/blob/feature/diy-DI/common/data/build.gradle.kts#L14