Kotlin Multiplatform Mobile interops with Kotlin M...
# multiplatform
l
Kotlin Multiplatform Mobile interops with Kotlin Multiplatform, correct? I mean, if I have a K/M subproject, and a KMM subproject, they will be able to depend on each other, right?
j
There's no real difference between KMM and KMP. KMM is an acronym that JetBrains no longer uses, that was used to describe the specific usage of Kotlin Multiplatform for sharing mobile code between Android and iOS. It works similarly to add other native, JS, or Wasm targets.
☝️ 4
l
@Jeff Lockhart But doesn't KMM use separate projects, compared to K/M's source sets?
j
I'm not sure I understand your question. Kotlin Multiplatform supports all of these targets. A "KMM" project would just be targeting
jvm
or
android
(depending if Android APIs are needed), as well as
iosArm64
,
iosX64
, and
iosSimulatorArm64
for all of iOS's targets. But you could also add any of the other supported native targets or
js
to the same project, as well as both
jvm
and
android
together (to support Android and desktop JVM). As long as you're using common Kotlin APIs or libraries that support all of your targets, or implement `actual`s that cover all your platform source sets for any
expect
APIs, then you can support as many platforms as you want.
For example, my library, Kotbase, supports Android, JVM, iOS, macOS, Linux, and Windows. You could use it in a KMP project that supports any subset of those targets.
l
Oh, I was pretty sure KMM uses entire subprojects.
j
For the native platform apps, you can have separate subprojects/modules, e.g. androidApp, desktopApp, etc. The iOS app needs to be an Xcode project itself. The shared KMP code will be in the same subproject/module. You can also have the platform-specific code in this same shared subproject/module though, within the platform source sets.
l
Wait, then how does one use a subproject instead of a sourceset?
j
I migrated an example app for my library from multiple to a single module in this commit. You can compare the project before and after the commit to see the difference.
🙏 1