Hi everyone :wave: I have a fully working Android ...
# multiplatform
a
Hi everyone 👋 I have a fully working Android app built with Kotlin + Jetpack Compose, and I'm considering migrating it to Kotlin Multiplatform (KMP). I’d love to hear from anyone who has actually gone through this process: Have you migrated an existing Compose app to KMP? How smooth (or painful 😅) was the transition? What were the biggest challenges? (libraries, navigation, architecture, etc.) Would you recommend migrating, or starting KMP from scratch instead? Any real-world experiences or advice would be highly appreciated 🙏
k
Are you using KMP or CMP? I have migrated an Android app to CMP for both Android and iOS. Process was pretty smooth if you're already using Jetpack Compose since most can just be moved to commonMain and just works. Only the Android specific stuff needs to be migrated. Biggest challenges are definitely third party libraries which do not have a CMP version or platform specific stuff like permissions (both handle it similar, but just not quite the same). There are libraries for handling the permissions, but back then I wasn't too confident about the libraries, so opted to do it myself (had a problem with another library, which I needed to migrate to my own implementation later on, which was a pain). The third party library stuff or platform specific stuff, just make a plan in what you need and what the library needs from common before starting. This way you can create the expect in advance with everything you need. Third party I usually do in SPM and provide an interface in the commonMain and an accessor through a companion object for example. Then implement the interface in Xcode and handle the library stuff there. My recommendation is starting a new CMP project and just start copying most stuff to the correct folders. This way the rest of the folder structure for CMP is already correct. Hope this helps!
❤️ 2
s
Halfway done for my app. Started with Koin (Koin compiler) and Room. Worked quite nice, I lost some time as I misunderstood "required syntax" by the Koin Compiler (make sure to use create(::functionProvidingDependency) instead of a "free form lambda". I stumbled on this e.g. on myRoom.myDao() which I tried to use directly instead of via myFunction = myRoom.myDao()
I got some hints from other users here about migration, the answers might help you too. https://kotlinlang.slack.com/archives/C3PQML5NU/p1774622542391449 Note that AGP 9 changes some things https://kotlinlang.org/docs/multiplatform/multiplatform-project-agp-9-migration.html So if you have an exisitng android app and a dd a shared module that's a good starting point as you then automatically have the separate Android module
l
I did it 8 months back, and worse, migrating from XML Views to CMP then KMP. CMP to KMP, I'd say the pain varies greatly depending on what your app does. I hit a lot of bumps because I checked a lot of bad cases: widgets, using Google Drive libraries, etc... Which don't have a KMP library just ready for you to use. For me the painpoints were: • How to choose the right CMP library? Or do I code it myself? ◦ When there a lib - do I trust those (I found one on github but didn't open source their code... did I want that? No). Also, not all are mature. ◦ One recommendation: run over to FileKit Hands-down saved me tens or hundred of hours to handle files in KMP. And the dev is reactive. ◦ Another reco: I ended up spinning out a couple of things I did for Android into separate external KMP libraries. Even if I'm the only user, It still feels, cleaner. So don't discard that possibility. • iOS & Android aren't the same beasts (as you know :p) ◦ You'll discover race conditions and over fundamental bugs never surfaced in Android - but yes, even from CMP. Or you'll discover you didn't do it exactly properly in Android but need to migrate some stuff to be really multi platforms. ◦ Your architecture choices were made for Android. And some will not be iOS compatible (Widgets, I'm frowning at you) ◦ Don't expect the first • Usual recos: ◦ Keep iosApp & androidApp thin wrappers • Gradle as usual will give you headaches ◦ But know that you can propagate variables from KMP package to Android/iOS , with some pain. You can check my main build file for some ideas of KMP parckages I ended up trusting, and have variables available in code & app config (like version name/code) https://github.com/licryle/Android-HSKFlashcardsWidget/blob/main/crossplatform/build.gradle.kts • cocoapods vs. frameworks: ◦ Originally cocoapods seemed too daunting and not needed, but I ended up needing other cocoapods and hit incompatibilities, so I ended up migrating it all to cocoapods. Maybe start directly with those. I'm no longer a professional software engineer (or rather re-ramping up); and I know 0 swift/iOS dev; so take some of these recommendations with a grain of salt though 🙂 But I hope that will help!
kodee loving 1
z
Migrating my Android-only application from the traditional Activity-based architecture to Kotlin Multiplatform (KMP) with Jetpack Compose for both Android and iOS was one of the biggest technical challenges I’ve faced. The hardest part was succeeding in updating the existing app built with the old architecture into the new KMP + Jetpack Compose application, especially since it was developed as a completely new project. Thanks God, the result was worth it. Today my app “أبواب النحو” is running successfully on both Android and iOS, available on Google Play and the Apple App Store. Now development and maintenance are much smoother. Instead of managing two separate codebases, updates and improvements can be implemented more efficiently across both platforms.