Hi team, Could you please help me understand the b...
# multiplatform
v
Hi team, Could you please help me understand the best approach for this setup? I currently have an app with separate packages for Android and iOS — both are fully implemented but maintained independently. Now, I want to migrate this app to Kotlin Multiplatform (KMP). I’m a beginner, so I’m a bit confused about the right way to proceed. Initially, I created a new KMP package and started re-implementing the logic from the Android package into the
commonMain
and
androidMain
modules. However, since the entire implementation already exists in the Android package, I’m wondering if redoing it in KMP adds much value. I also considered another approach: keeping both the Android and KMP packages locally, making the KMP module a library, and adding it as a dependency in the Android project. Then, I could move the shared code into the KMP module while keeping Android-specific files in the Android package. Could you please suggest which approach is better? Also, note that the Android and iOS packages are currently built using different build systems. And to get the app fully working in KMP, do I need to make changes only in the KMP package or in both the Android and KMP packages?
r
There are two main ways to do a KMP app for iOS + Android: • Shared UI + shared core logic: ◦ Compose Multiplatform (CMP) for UI ◦ One build setup (KMP/Grade), but it can produce artifacts for both iOS and for Android ◦ Access platform-specific APIs via expect/actual • Native UIs + shared core logic: ◦ Shared core logic as a KMP library ▪︎ Access platform-specific APIs via expect/actual ▪︎ Builds to artifacts importable by Android and iOS projects ◦ Android UI ▪︎ Regular android UI (probably jetpack compose) ▪︎ Regular android build system ▪︎ Imports shared core logic as a library ◦ iOS UI ▪︎ Regular iOS UI (probably SwiftUI) ▪︎ Regular iOS build system (probably Xcode) ▪︎ Imports shared core logic as a library
v
can i know which is best approach
r
It depends if you value having Native UI on iOS, or only writing the UI once
Overall setup is simpler with shared UI (CMP), but having Native iOS UI might be important for some apps/developers
v
• Shared UI + shared core logic: ◦ Compose Multiplatform (CMP) for UI ◦ One build setup (KMP/Grade), but it can produce artifacts for both iOS and for Android ◦ Access platform-specific APIs via expect/actual this will become complex i guess
for this we have to integrate totally
• Native UIs + shared core logic: ◦ Shared core logic as a KMP library ▪︎ Access platform-specific APIs via expect/actual ▪︎ Builds to artifacts importable by Android and iOS projects ◦ Android UI ▪︎ Regular android UI (probably jetpack compose) ▪︎ Regular android build system ▪︎ Imports shared core logic as a library ◦ iOS UI ▪︎ Regular iOS UI (probably SwiftUI) ▪︎ Regular iOS build system (probably Xcode) ▪︎ Imports shared core logic as a library • since i had seperate android package and seperate ios package with fully working implementation now if i create a new package for kmp and add kmp as library in android package and moving shared code from the android package to kmp package will make sense?
r
Well you'd either be converting the existing android (jetpack compose) UI into Compose Multiplatform, or trying to integrate the Kotlin shared core logic lib into the existing iOS UI. I think the shared UI (CMP) option would be easier. You can get some weird config/compatibility issues when trying to include a KMP library into a regular iOS app
v
• then you are saying this is the best way Shared UI + shared core logic: ◦ Compose Multiplatform (CMP) for UI ◦ One build setup (KMP/Grade), but it can produce artifacts for both iOS and for Android ◦ Access platform-specific APIs via expect/actual
r
Probably, but I do not know your exact project. I think it's the best place to start, though
v
do we had any design docs on the approaches of integrating an app into kotlin multiplatform