Home > other >  How to convert Kotlin project to Kotlin Multiplatform Mobile after the project completion?
How to convert Kotlin project to Kotlin Multiplatform Mobile after the project completion?

Time:03-18

I have built a code in Android Studio with Kotlin. I initially haven't set it up as a Kotlin Multiplatform Mobile project and I would like to bring it now also on iOS. Is there a way to "convert" it to a Kotlin Multiplatform Mobile at this stage? Thanks

CodePudding user response:

This is a multi-step process:

  1. You'll need to adapt your build configuration - change build.gradle.kts to a KMM setup. Examples you can find at PeopleInSpace and KaMPKit repos
  2. You have to make your Android code platform agnostic in order to share pieces with iOS

The changes you need to make depends on how many Android dependencies you have, how much platform-specific code you wrote and how much you want to share with iOS.

I wouldn't underestimate how big of a refactor this might need, as there are loads of platform-specific things that as an Android devs can overlook (JUnit, File, Dates are just a few examples, where we commonly used JVM libs)

I'd recommend starting small, creating a shared module with a KMM configuration, then step-by-step moving things to shared

Reach out if you have more questions

CodePudding user response:

Checkout this detailed video that explains this process https://www.youtube.com/watch?v=X6ckI1JWjqo

You would need to switch using Kotlin native libraries for common shared code, so depending on that, you might have more or less work to do.

On top of that, you would need to use strategies around dependency injection, common view model layer etc.

  • Related