Hi folks! I hope you all good! Had a quick questio...
# multiplatform
m
Hi folks! I hope you all good! Had a quick question. I鈥檓 building an android app with compose and kotlin (centralizing the view models and the logic in a Shared module KMP), if i want to implement the iOs app Ui, can I move the Compose UI from the android module to the Share module and it will work? Or the compose multiplatform need tricky things? Thank you in advance for your response 鉂わ笍
j
Both yes and no, depends which libraries using in android app 馃檪 In general its not an issue, when doing plain Kotlin things not platform dependant things, like androidx lifecycle library or such.
g
You will need to also config the main app that opens inside iOS and Android , should be quick , but as Joel says , if you are using specific Android libs you will need to find a multiplatform one to switch it to
I recommend precompose as it has navigation, DI and view model with all lifecycle handled
j
What you can do, go to like kmp.jetbrains.com, create a new project. Then test copy paste your code in current Android app into the androidMain folder for Kotlin files. And res things as usual in root folder of androidMain. Then you will notice which things work vs not.
鉂わ笍 1
If you use Ktor and Koin they already multiplatform. androidx datastore, android collection and androidx paging I think is KMP as well. You cannot use like androidx navigation compose in KMP. For that I would replace with Circuit, I think is the closest you get. You can ofc also check Voyager and Precompose if prefer those.
And for the things you cannot directly share in common/shared, you can still using native Android things, by using expect/actual with interfaces and such, to be able call Android SDK things from commonMain 馃槣
So in each platform, even iOS, Wasm, Desktop etc youre able to implement native things as you wish, and even get interop in each target platform.
m
I started already with the multiplatform template and i鈥檓 already using Ktor and Koin for the request, in fact, i got all the repositories and view models on the Shared module, but yes i used some libraries for Ui things, like a graph library, but is it鈥檚 writen in compose, that makes it ? Or should it be explicit compose-multiplatform?
j
Compose multiplatform using a separate gradle plugin, which syncing all androidx compose libs, such as Material 3 etc. Just be aware depending on CMP version using, the combination of androidx compose libs available differs. You can override it, but I dont recommend doing so. Meaning could almost see CMP of being equivalent to BOM thing, not same but similar. In that way it will be possible to use all compose libs in desktop, iOS, Android from commonMain 馃槣
Not entirely sure whats happening if a library itself using transitive dependency to compose. I think as same package names used in CMP, it will be resolved correct if the lbirary added in commonMain, but not entirely sure to be honest.