8

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?

S Haque
  • 6,881
  • 5
  • 29
  • 35

1 Answers1

8

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)

Róbert Nagy
  • 6,720
  • 26
  • 45
  • 1
    Thank you for your answer. I have seen this library but I am looking for platform support for this common use case. – S Haque Jun 01 '21 at 03:08
  • @CodeCameo there isn't platform support yet – Róbert Nagy Jun 01 '21 at 06:24
  • Thank you @RóbertNagy for this ‍♂️!!! Glad you shared it. It's really nice that someone is contributing with adding this support before there's something in KMM for it. – Ovi Trif Apr 07 '22 at 15:33