@@ -7,7 +7,7 @@ import com.squareup.kotlinpoet.TypeSpec
77
88plugins {
99 alias(libs.plugins.kotlin.multiplatform)
10- alias(libs.plugins.android)
10+ alias(libs.plugins.android.application )
1111 id(" com.github.gmazzo.buildconfig" )
1212}
1313
@@ -25,10 +25,21 @@ kotlin {
2525
2626android {
2727 compileSdk = 36
28- namespace = " com.github.gmazzo.buildconfig.demos.kts_multiplatform"
28+ namespace = " com.github.gmazzo.buildconfig.demos.android"
29+ buildFeatures.buildConfig = true
30+ defaultConfig.minSdk = 21
31+
32+ flavorDimensions + = listOf (" brand" , " env" )
33+ productFlavors {
34+ create(" stage" ) { dimension = " env" }
35+ create(" prod" ) { dimension = " env" }
36+ create(" bar" ) { dimension = " brand" }
37+ create(" foo" ) { dimension = " brand" }
38+ }
2939}
3040
3141dependencies {
42+ commonMainImplementation(libs.uriKMP)
3243 commonTestImplementation(libs.kotlin.test)
3344}
3445
@@ -37,29 +48,53 @@ buildConfig {
3748 buildConfigField(" IS_MOBILE" , expect(false )) // with a default
3849 buildConfigField(" PLATFORM" , expect<String >()) // without a default
3950 buildConfigField(" DEBUG" , expect(false )) // to be changed by an Android variant
51+ buildConfigField(" com.eygraber.uri.Uri" , " ENDPOINT" , expect(expression(" Uri.parse(\" https://api.example.com\" )" )))
52+ buildConfigField(" PRODUCT_VALUE" , expect<String ?>(null ))
53+
54+ forClass(" i18n" ) {
55+ useKotlinOutput { topLevelConstants = true }
56+
57+ buildConfigField(" i18n_hello" , " Hello" )
58+ buildConfigField(" i18n_kind" , expect<String >())
59+ }
4060
4161 sourceSets.named(" androidMain" ) {
4262 buildConfigField(" PLATFORM" , " android" )
4363 buildConfigField(" IS_MOBILE" , true )
4464 buildConfigField(" ANDROID_VALUE" , " anAndroidValue" )
65+ forClass(" i18n" ).buildConfigField(" i18n_kind" , " android" )
4566 }
4667
4768 sourceSets.named(" androidDebug" ) {
4869 buildConfigField(" DEBUG" , true )
4970 }
5071
72+ sourceSets.named(" androidStage" ) {
73+ buildConfigField(" com.eygraber.uri.Uri" , " ENDPOINT" , expression(" Uri.parse(\" https://stage.api.example.com\" )" ))
74+ }
75+
76+ sourceSets.named(" androidFoo" ) {
77+ buildConfigField<String ?>(" PRODUCT_VALUE" , " fooValue" )
78+ }
79+
80+ sourceSets.named(" androidBar" ) {
81+ buildConfigField<String ?>(" PRODUCT_VALUE" , " barValue" )
82+ }
83+
5184 sourceSets.named(" jvmMain" ) {
5285 buildConfigField(" PLATFORM" , " jvm" )
5386 buildConfigField(" JVM_VALUE" , " aJvmValue" )
87+ forClass(" i18n" ).buildConfigField(" i18n_kind" , " jvm" )
5488 }
5589
5690 sourceSets.named(" iosMain" ) {
5791 buildConfigField(" PLATFORM" , " ios" )
5892 buildConfigField(" IS_MOBILE" , true )
5993 buildConfigField(" IOS_VALUE" , " anIOSValue" )
94+ forClass(" i18n" ).buildConfigField(" i18n_kind" , " ios" )
6095 }
6196
62- sourceSets.named(" jsMain " ) {
97+ sourceSets.named(" webMain " ) {
6398 // Customize the generator to add @JsName annotations to the generated object
6499 generator = object : BuildConfigKotlinGenerator () {
65100 override fun adaptSpec (spec : TypeSpec ) = spec.toBuilder()
@@ -71,6 +106,10 @@ buildConfig {
71106 .build()
72107 }
73108
109+ forClass(" i18n" ).buildConfigField(" i18n_kind" , " web" )
110+ }
111+
112+ sourceSets.named(" jsMain" ) {
74113 buildConfigField(" PLATFORM" , " js" )
75114 buildConfigField(" JS_VALUE" , " aJsValue" )
76115 }
0 commit comments