Build config values depending on target with Kotlin Multiplatform

Tired of using expect/actual for managing build config values across multiple targets in Kotlin Multiplatform? Discover a streamlined solution to handle platform-specific configurations, making your setup cleaner and more maintainable!


buildkonfig { 
    packageName = "com.smthg.app"
 
    defaultConfigs {
        // apiKey is overridden in targetConfigs.
        buildConfigField(type = STRING, name = "THIRD_PARTY_API_KEY", value = "")
    }

    targetConfigs {
        create("android") {
            buildConfigField(
                type = STRING,
                name = "THIRD_PARTY_API_KEY",
                value = project.rootProject
                    .getLocalProperty("third_party_api_key_android")
                    .orEmpty()
            )
        }

        listOf(
            "iosX64",
            "iosArm64",
            "iosSimulatorArm64",
        ).forEach { iosTarget ->
            create(iosTarget) {
                buildConfigField(
                    type = STRING,
                    name = "THIRD_PARTY_API_KEY",
                    value = project.rootProject
                        .getLocalProperty("third_party_api_key_ios")
                        .orEmpty