I have come to a conclusion that sharing a gradle ...
# compose-desktop
o
I have come to a conclusion that sharing a gradle module having pure Kotlin Composables between an android app module and a desktop app module is actually impossible (because they use different artifacts of Compose), but copying the same code will work correctly for each module. Please tell me I’m wrong : /
s
So where do limitations come into play? We couldn’t create a JVM library and share it between Android and JVM which it sounds like @Oussama Haff. is trying to do, but we could create a multiplatform library and share it between Android and JVM, where shared UI is in the common layer? Right?
1
j
Yeah, so there are a few things here. • JVM vs MPP - Both Desktop and Android are JVM-capable, but they don't always have the same actuals for some of the lower-level APIs. If your composable depends only upon JVM class names that are not platform-specific expect/actuals, I think the same jar file could be used on both platforms. Most composables I think don't rely on platform-specific implementations, so this should be fine. • Maven Dependencies - When you publish a library on maven, you typically specify dependencies. This gets tricky, because do you depend on the artifacts published by Jetbrains or on the artifacts published by Google? Whichever one you choose, anyone using the other provider will likely get tripped up by gradle's dependency resolution. I believe it is possible to force the resolution (perhaps we can provide some docs on this), but this is where most people get tripped up I think. TLDR: Yes, you can create shared UI in the common layer, but there are a couple of rough edges that might trip you up if you don't set them up properly.
👍 1
o
Thank you Jim, Nickolay for your response : ) @olonho, @jim, @Leland Richardson [G] Don’t you think that it would be great if we had 3* artefacts exposed to developers ? • Compose JVM (The pure version shared between G and JB and can work on both Android / Desktop ) • Compose Android (used only with Android Gradle plugin) • Compose Desktop (can’t be used with AGP) Where the use of two different platforms in the same module (or dependent module) is prohibited. *I believe that in the real world is much more that three artefacts.
j
@Oussama Haff. There is no "Compose JVM", as both Android and Desktop are JVM but need different actuals for some expects. But aside from that, yes, the build of Compose published by Jetbrains is already published as an MPP project that can be used with Android and Desktop (choose one or both). I'm not entirely sure what your question is asking, but all the artifacts you need for the above use cases are already published.