https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
x

xxfast

05/30/2021, 4:19 AM
is there a way use jetpack compose in
androidMain
in kotlin multiplatform module?
c

CLOVIS

05/30/2021, 8:44 AM
a

Arkadii Ivanov

05/30/2021, 9:13 AM
Yes it is possible. You will need to apply this workaround: https://github.com/avdim/compose_mpp_workaround
I have some samples that use Jetpack Compose in multiplatform modules in
androidMain
https://github.com/arkivanov/Decompose/tree/master/sample
x

xxfast

05/30/2021, 11:38 AM
I’ve tried the workaround - it does work. Unfortunately when i tried to set up a desktop module with compose-for-desktop, and if i were to depend on this
:common
module with compose in it’, causes this weird cryptic error
Copy code
androidx.compose.compiler.plugins.kotlin.IncompatibleComposeRuntimeVersionException: You are using an outdated version of Compose Runtime that is not compatible with the version of the Compose Compiler plugin you have installed. The compose compiler plugin you are using (version 1.0.0-beta05) expects a minimum runtime version of 1.0.0-beta05.
a

Arkadii Ivanov

05/30/2021, 11:41 AM
If you are using Compose for Desktop, then you don't need the workaround. The workaround is only required for Jetpack Compose. There are many examples available: https://github.com/JetBrains/compose-jb/tree/master/examples Also there is a dedicated channel for Compose for Desktop: #compose-desktop
x

xxfast

05/30/2021, 11:43 AM
I see - thanks for the direction
👍 1
i was trying to use both jetpack compose in
androidMain
as well as depend on the
commonMain
of the same module in my jetbrains compose desktop module - which I think was causing the compose compiler plugin (from the workaround) to see jetbrains compose as an outdated version.
a

Arkadii Ivanov

05/30/2021, 12:25 PM
Yeah, probably we should not mix Desktop and Jetpack Compose at the moment. Compose for Desktop is actually multiplatform, and so can be used to write shared UI between Android and Desktop.
x

xxfast

05/30/2021, 12:26 PM
yeah, lack of ui-tooling preview support is the only thing holding me back
a

Arkadii Ivanov

05/30/2021, 12:28 PM
Hopefully we'll get the preview for MPP Compose soon. At the moment you can organise a separate desktop app for preview purposes. It compiles faster than Android.
x

xxfast

05/31/2021, 2:42 AM
@Arkadii Ivanov Got one last question for you. Can a pure android project use jetbrains’ compose composables? (as they seem to share the same package name)
a

Arkadii Ivanov

05/31/2021, 5:38 AM
Yes, they can
But better to not mix both variants.
3 Views