Hi everyone, In Koltin multiplatform project, I ha...
# multiplatform
s
Hi everyone, In Koltin multiplatform project, I have an object class in shared module in commonMain and i am trying to access and update some variables of that object class from native android and ios project, From android its working fine, but its showing this exception in ios project:
Copy code
Uncaught Kotlin exception: kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen com.buildingengines.sharedmoduletenant.core.service.KmmServiceLocator@1518f08
How to solve this problem, cant we access and update shared module object class variables from swift ios? any workaround for this, Guys Please help. i am stuck with this. I need singleton class in shared module and then inject some native android and ios dependencies into that class on app startup.
l
Are you using the new memory model?
Under the old memory model, all global variables get frozen. The new memory model doesn’t have the same limitation.
s
Means? i did not get you. which memory model you are referring? Are you saying about kotlin version/
google 1
I am using the latest version of kotlin as well 1.6.10 and i read about this frozen state of singleton class in kotlin native. But is there any solution for this?
The Kotlin/Native team created a new memory model, but since it’s still experimental, they haven’t made it the default yet. I’ve been using it and haven’t had any issues caused by the memory model, but YMMV.
s
Let me try it.
Hey @Landry Norris thanks buddy. It worked but faced http client engine related issue after using that, but that is resolved by creating separate client in androidMain and iosMain. Thanks buddy .
l
Glad I could help
I also saw issues with the CIO driver (I don't think it's ready for the new mm yet), so I used expect/actual for the client.
s
Yes i also faced the issue with ktor http client engine at that time, so i used the native implementatios there.