https://kotlinlang.org logo
Title
d

Daniele B

06/25/2021, 8:28 PM
I have finally added the Desktop app to the D-KMP sample: https://github.com/dbaroncelli/D-KMP-sample (featured by JetBrains in their latest KMM update) At the moment the composables for Android and Desktop are separate, in their own project directory: /*androidApp*/…../composables /*desktopApp*/…../composables They are exactly the same apart from a very small difference (the Android app uses the
BackHandler
composable too). All the rest is identical, as they are pure layout, with NO(!) AACViewModel/AndroidNavigation/DI dependencies whatsoever. My idea was to actually create an additional multiplatform project directory “*composables*”: /_*composables*/commonMain_ */composables*/androidMain */composables*/desktopMain just for composables shared by Android and Desktop, but I found it incredible hard, as Gradle doesn’t seem to like me. If there is anyone here who understands Gradle and the JetBrains Compose plugin very well, and has 15 minutes to spare to move the composables to their own separate project, it would be very appreciated.
b

Brian G

06/25/2021, 8:45 PM
Take a look at the jetbrains compose samples, there are some that share some code between Android & desktop. Due to limitations in Kotlin multiplatform plugin, I think you have to use source directories, not source sets, to share the code.
d

Daniele B

06/25/2021, 8:48 PM
I have spent some hours, trying to setup the project as in this template: https://github.com/JetBrains/compose-jb/tree/master/templates/multiplatform-template but I kept having issues. I would need a little support by someone who understands this stuff properly.
u

uli

06/25/2021, 11:25 PM
Here is a really minimal KMM example including Compose, ComposeDesktop, ComposWeb, KotlinReact, iOS/SwiiftUI. Compose, ComposeDesktop share some simple components. https://gitlab.com/uluckas/s2-CrossPlatform-Test Feel free to get back if you have any questions.
d

Daniele B

06/25/2021, 11:49 PM
Hi @uli, thanks for the reply. In reality my issue is not with configuring the specific apps, but with configuring a multiplatform project directory (“/_*composables*_”) where to place all composables that are common between the Android and Desktop apps
u

uli

06/26/2021, 9:09 AM
Exactly. Take a look at e.g. MainScreen.kt in the project i synced. It is shared between Android and desktop.
d

Daniele B

06/26/2021, 12:20 PM
Thanks @uli, I was able to set it up!!! it’s wonderful!!! Composables are now defined in just one place and shared by both Android and Desktop!
I made it!
🎉 2
:jetpack-compose: 2
👏 2
:kotlin-intensifies: 2