Reputation: 7271
In native android project, we can define BuildConfig variables which can be change based on the selected build type (debug or release). For this we can add the code below in app level gradle file
buildTypes {
release {
buildConfigField 'String', "BASE_URL", '"https://stackoverflow.com/"'
}
debug {
buildConfigField 'String', "BASE_URL", '"https://qa.stackoverflow.com/"'
}
}
I am looking forward to create global configuration variables like this can be accessed from shared module and from Android and iOS module if possible. How I can achieve this?
Upvotes: 9
Views: 3184
Reputation: 7602
You could check out BuildKonfig
For an example:
buildkonfig {
packageName = "com.halcyonmobile.multiplatformplayground"
val baseUrl = "baseUrl"
defaultConfigs {
buildConfigField(
Type.STRING,
baseUrl,
"https://halcyon-multiplatform-backend.herokuapp.com/"
)
}
defaultConfigs("dev") {
buildConfigField(Type.STRING, baseUrl, "http://0.0.0.0:8080/")
}
}
(Example from https://github.com/halcyonmobile/MultiplatformPlayground/blob/master/common/build.gradle.kts)
Upvotes: 8