I have a multi-module Android app that I’m migrati...
# multiplatform
m
I have a multi-module Android app that I’m migrating to KMP (initially with Android and iOS targets). I’m starting with my core library module which has some Android-specific code that needs to be exposed to other modules (Android-only modules and Android code in KMP modules). As I understand it, Android code in a KMP module is not exposed, so I need to create an Android-only module for that. I’m curious what the standard/typical way to group these modules is: 1️⃣ core-android (core/android/), core-shared (core/shared/), or 2️⃣ android-core (android/core), shared-core (shared/core)
3️⃣ 3
j
You can have Android-specific code in a KMP module that other KMP modules' Android targets and regular Android models can see
h
You don't need to create an Android module. As your project is targeting Android and iOS platforms, each KMP module will have 3 source sets which are commonMain, androidMain, and iosMain. You can have full access to Android-specific codes in the androidMain source set. I suggest you to convert each Android module to a KMP module. Write platform independent codes in the commonMain and for parts that are tied to the Android platform, use expect/actual mechanism and delegate implementation to the androidMain and iOSMain. As you currently have android project, it might be better to complete androidMain first and then complete iosMain.
👍 2
m
Thanks guys. Not sure where I heard that
commonMain
was providing the public API for the KMP module, but I guess I was mistaken. So it looks like the only Android modules would be the app module and any android-specific feature modules (e.g. homescreen widgets).
h
Yes your project will have only one Android module. You can add KMP modules to your android module as a dependency.
m
I think it was Chat GPT leading me up the garden path