Hey all, I have an Android app with Jetpack Compos...
# multiplatform
s
Hey all, I have an Android app with Jetpack Compose that i want to migrate to KMP. I've already added the shared module, now I need to migrate Compose and other things like ViewModel, Room etc. I wanted to start with Compose to Compose Multiplatform but could not find a guide for this. Is there one and I just missed it or do I need to "reverse engineer" from a fresh KMP project with Compose Multiplatform? Thanks!
c
It’s basically just exchanging the Jetback Compose Libraries with their Jetbrains Compose counterparts (with lots of version fiddling 😅 ) https://kotlinlang.org/docs/multiplatform/compose-multiplatform-jetpack-libraries.html
✅ 1
z
This guide migrates a project that uses Compose from Android to KMP https://kotlinlang.org/docs/multiplatform/migrate-from-android.html
✅ 1
s
Recently I did the similar thing with one of the existing Android projects with compose UI. We followed the following steps while migrating to CMP+KMP. This project recently went to production. 1. In existing Android project, replaced all Java based code with KMP compatible Kotlin APIs. commonMain can't contain Java code. 2. Meanwhile, created KMP module and wrote entire network layer from scratch and migrated repository and ViewModels class too. 3. Migrated Room database as it was easy due recent stability. 4. At the end we migrated Compose UI to CMP as we were expecting most of the things to work in CMP since CMP is built on top of Compose only but we had to introduce smaller fixes as and when required. The guild shared by @zsmb can do the perfect Job. We followed almost the same steps.
✅ 1
b
Having been working with it for a while now, I would start with a fresh project and move your code in, fixing any of the problems as you go. By all means you can retrofit your current project and do it that way, but i just like how the project turns out when i do it that way. Make no mistake, unless you knew what you were doing in the first place, you probably did a lot of things that are android specific, and you will have to fix all of that. A new project lets you rebuild it piece by piece, from the top, using your old code. It also gives you a chance to do things differently if you wanted to change things around.
s
@Brill was thinking about that too, but that would loose mit Git history. I ended up adding a shared modul and I am mostly done. Worked quite ok. Most issues coming from some misunderstandings with Koin compiler usage 😉