Does anybody have a link to an article explaining ...
# compose-desktop
a
Does anybody have a link to an article explaining how Compose Multiplatform works? (e.g. how the compiler is not bundled with the android environment even though contains the androidx in the name etc)
👀 1
j
So first, androidx is just the package name. You can write a Java file and put kotlin as the package name. There's nothing intrinsic about the androidx package that means Android, although usually it is used that way. The AndroidX collection library is a jar that works perfectly fine on the JVM, for example.
Second, Kotlin for Android and Kotlin for JVM are the same thing and they both produce Java bytecode as their output.
Third, Kotlin multiplatform has the expect/actual mechanism which allows any actual Android dependencies to be replaced at compile time with equivalent JVM ones
Fourth, JetBrains built skiko, a Kotlin JVM project that exposes the Skia rendering engine to Kotlin JVM. Skia is also the rendering engine on Android and it's API is very closely mirrored in the low-level Android graphics APIs
So basically Compose for Desktop (JVM) runs the same Skia that Android runs, compiles the same code that Android uses for Compose UI, and expect/actuals about 0.1% of the code so that they can replace hard Android dependencies with equivalent JVM ones.
a
Thank you! That’s really helpful!
j
Also the Compose compiler operates on Kotlin IR so it has always worked for JVM. You were able to compile the runtime for the JVM and use the Android Compose compiler three years ago. Getting Compose UI was where the work actually was.
r
Yeah the runtime was never Android (nor UI) specific
And we had abstractions/expects in a various of places in the early designs to enable MP
a
Thank you all. Much clearer now.