Ask Your Question

Revision history [back]

Build variables in Kotlin multiplatform can be accessed by creating a separate Gradle module and defining the variables in the build.gradle file.

In the common module, create an interface for the variable and implement it in the platform-specific modules.

For example, in the common module:

interface BuildConfig {
    val API_KEY: String
}

In the Android module:

object BuildConfigImpl : BuildConfig {
    override val API_KEY: String = com.example.android.BuildConfig.API_KEY
}

In the iOS module:

actual object BuildConfigImpl : BuildConfig {
    actual override val API_KEY: String = NSBundle.mainBundle.objectForInfoDictionaryKey("API_KEY") as String
}

Then, in your code, you can access the build variable like this:

val apiKey = BuildConfigImpl.API_KEY