https://kotlinlang.org logo
Title
p

Priyanshu Jain

04/05/2023, 8:51 AM
Hey. I have published a kotlin-multiplatform library on maven and then I am importing it into a sharedModule which is shared between both android and iOS app. When, the library is published, it publishes multiple packages, one for each target. When I use any class or object from the hosted library into my apps, I am facing a very weird issue. The android app during runtime will pull in some objects from one package (say example-module) while some it pulls from a different target package (say example-module-iosx64). I have only added a dependency of example-module in my shared module's build.gradle file, not any target specific module. Am I doing something wrong here?
r

russhwolf

04/05/2023, 2:52 PM
I'm not sure I understand the question, but Kotlin Multiplatform libraries are published using gradle metadata that allows you to just add a dependency like
example-module
and it will automatically pull in the platform specific artifacts like
example-module-iosx64
when building for the relevant platform.
p

Priyanshu Jain

04/05/2023, 3:08 PM
Yes. But, the issue that I am facing is that when building on android, instead of only pulling in from
example-module-android
, some classes and objects are being pulled in from
example-module-iosx64
. So, I am using a string variable in the
commonMain
of the library to switch between different test environments like stage, production etc. Default value of this variable is set to production. Then, in my app's main activity I set this variable based on the environment so that I can get different base urls depending on the config variable's value. But, I get the production base urls even if I set the config variable to stage. I attached debugger and found that the config variable does get set in the
example-module-android
but the urls are being fetched from the
example-module-iosX64
target which is why I end up getting the default urls. Hope this explained the situation better. Thanks
r

russhwolf

04/05/2023, 3:18 PM
That helps some, but it's hard to give advice here without seeing the actual code. It also doesn't sound like it's an issue specific to any of our Touchlab tools, so you might get more help in #multiplatform.
p

Priyanshu Jain

04/06/2023, 5:31 AM
Thanks. Will ask on #multiplatform then.