Hi! I’m starting with KMP, and I’m having some pro...
# multiplatform
a
Hi! I’m starting with KMP, and I’m having some problems to understand how to organize my modules. Currently I have three Apps: Web (with the old Compose Web), Desktop and Android (sharing UI with Compose Multiplatform). I have one common module where I have the shared Compose MP code, and I found the issue that DropdownMenu is not available in the MP code, and I need to implement it for Android and Desktop. So I thought about using expect/actual, but then I would need to add an
actual
for web, which is not using it. Also, as the three are using Compose, I could create expects for screen composables, and do the actual implementation in the two Compose variants. But again, I would need to repeat the code for Android and Desktop, which use the same code. So, in my head, it would be helpful to have something like: • One common module for web and compose KMP variants • Another common module for Desktop and Android, to share their Compose code That would allow me to have the expect/actual of the screens in the first module, and the expect/actual of the Dropdown in the second module. But I’m not sure if that’s possible. And if it is, do you happen to have a sample code to check the Gradle configuration of that? Thanks in advance!
👍 1
so I guess I can create several multiplatform modules 🤔
g
Another common module for Desktop and Android, to share their Compose code
I guess you could create another
sourceSet
and let
desktopMain
and
androidMain
depend upon it. something like this should work
Copy code
val commonDesktopAndroidMain by creating {
  dependsOn(commonMain)
  desktopMain.dependsOn(this)
  androidMain.dependsOn(this)
}
And then use
commonDesktopAndroidMain
to define your shared code
a
That's a simpler solution yeah! I'll try that, thanks
This worked amazingly well. Thanks @Giancarlo Buenaflor
g
nice! good to hear 🙂