Hello everyone, I need to develop a KMP library th...
# multiplatform
m
Hello everyone, I need to develop a KMP library that should be used on Android/iOS/React(Web) as the core library and only build UI on top of it natively. Anyone have a sample project for this kind of development? Is it efficiently possible? How far can I go in the core module, can I go as far as shared ViewModels?
c
what research did you do so far? I guess this is perfect starting point to all your questions: https://www.jetbrains.com/help/kotlin-multiplatform-dev/multiplatform-create-first-app.html#next-step
m
I have successfully made a full sample with KMP + CMP but I was wondering if I can remove the CMP layer and just use the KMP library on all platforms and develop the UI with native tools instead of CMP
c
what makes you think you cannot remove the CMP part?
the link above is exactly that use case. KMP with native UI.
thank you color 1
f
Hey, Mohamed I would just say, watch out for the JS target, since I think it can get quite hard to maintain in a side project that I did, the idea was having a Android/iOS/Web (svelte) app using a Shared package. And while the iOS part wasn't that hard using SKIE plugin, the JS wasn't as straight forward. here are a list of things that I found difficult. •
suspend
functions do not have a counter part in JS, so you need to create wrappers for your suspend methods that wrap them in a JS
promise
. This can get solved using the suspend-transform plugin • You might already know that you need to mark exported things with
@JsExport
, which might get annoying • Dependency Injection might be hard as well, since you need to access the concrete implementation, or you need to crate a JS object that lazily loads your dependencies with the concrete implementation • And lastly (and is something that I haven't solved already) is that if you want to have a i.e repository that returs a flow you will again, need to craete some kind of wrapper. Hope this helps!
🙌 2
k
Hi! Not sure if it's the best approach, but I managed to integrate a KMP module into a React/Vite app using Koin. Still missing Flow and ViewModel integration, but I believe it's a good starting point https://github.com/FelipeKoga/Vitamin.kt
🙌 1