Hello all! I'm thinking of converting some Android...
# multiplatform
Hello all! I'm thinking of converting some Android & iOS Apps to KMM Kotlin Multi platform Mobile. • What's your experiences when converting an existing mobile project to KMM? • What are the pain points and things you had to pay more attention to? • I use AndroidViewmodel in many ViewModels which depend on the Application Context, what is the best way to make this ViewModels non dependant on the Application Context?
I'd recommend starting with some code that's isolated well and has a simple API. Code that doesn't rely on any platform APIs is the best candidate. For example, one of the first KMM modules I experimented with was some code that validates national identification numbers for different countries. The API was simply a function that takes a NIN string and country code and returns a boolean. As you become more familiar with KMM, you can move from there to other parts of code that are common between both platforms, like data models and networking, utilizing available multiplatform libraries. Things become more complicated, the closer to the UI the code gets, like platform dependencies in view models, as you pointed out. The nice thing about KMM is you can adopt it incrementally, as you build out a common shared module.
Once you've got to grips with using expect/actual to remove all the Android specific things (like ViewModels) from your non-UI code, and you've got to grips with gradle, then the biggest pain is converting your third party libraries (Room, Retrofit, etc) to KMM libraries. I'm happy with Ktor, Kotlin datetime, Kotlin serialisation and SqlDelight now.
That is a good idea Jeff! Starting small and incrementally instead of trying to do everything at once. I might pick some common business rules and put them in the shared module.
adjpd yes I'll need to move from all those 3rd party libraries. Do you miss any specific functionality from Room, Retrofit, Hilt, dagger?
I would say the main painpoint is iOS developers working with the kotlin library, there’s still some annoyances with using some kotlin features like sealed classes. We’re trying to help with some of these issues at Touchlab with our Swift Kotlin work. You can also see the KaMPKit repo to see how we setup ViewModels so that we use AndroidxViewModels and a similar approach for iOS
Thanks Kevin. That is very nice, I'll take a good look into your projects.