Kotlin Multiplatform environment variables

Hello and happy holidays.

How do I make/use environment variables in Kotlin Multiplatform?

I am coming from Android, where I would declare build config fields for each build type (or flavor), and then access them through BuildConfig.java.

Is something similar possible in Kotlin Multiplatform?

Example where it would be used, a different base url for development/staging/production APIs.

I think you are confusing build environment and the actual application runtime environment. You can use environment variables in the build (see gradle tutorials for details). The runtime environment will obviously depend on the platform, it is resolved differently on different platforms.

1 Like


Thank you for answering. You are right, I would like to check in runtime which is the current evironment.

Can I in runtime in iosMain check what is the current active target selected in iOS app?

You can you use the expect/actual keywords to do this. See the demo project when you create a new kmm project in android studio. It uses a class called platform that returns different values based on the target it got compiled for.

I know about the expect/actual mechanism, Iā€™m asking the specific way to access current runtime iOS target in iosMain.