https://kotlinlang.org logo
Title
c

Colton Idle

06/09/2021, 7:53 PM
This might be better in #multiplatform but I'll ask here first. If I want to write a KMP/KMM application and I want to share composables with desktop + android, and then I want a common networking module for desktop + android + ios, how would you recommend the module structure?
/androidApp
/commonCode
  /commonMain
  /desktopMain
  /iosMain
  /androidMain
/iosApp
/desktop
or
/androidApp
/commonComposables
  /commonMain
  /desktopMain
  /androidMain
/commonCode
  /commonMain
  /desktopMain
  /iosMain
  /androidMain
/iosApp
/desktop
Basically would you just have a single common module and internally that somehow had both the shared networking code and shared composables (even no compose for ios ui) or just have two modules that are multiplatform modules. one for us and one for network?
👍 1
j

jim

06/09/2021, 7:57 PM
In Compose, we define a
jvmMain
which is a parent of both
desktopMain
and
androidMain
, so anything we want those two modules to share can be placed inside
jvmMain
You can see it here: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui/src/ I'm not suggesting this is necessarily better, just an option for your consideration.
👍 1
Also, in case it wasn't obvious how that works, you just make the source set
dependsOn
the other source set: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui/build.gradle;l=162
👍 1
x

xxfast

06/11/2021, 5:11 AM
I recommend nested modules
:android
:common
  /commonMain
  /desktopMain
  /androidMain 
  :ui
    /commonMain
    /desktopMain
    /androidMain