I'm trying to use the new <Android KMP Library plu...
# multiplatform
m
I'm trying to use the new Android KMP Library plugin in my Compose MP library project and I noticed that I can't display previews anymore - in my
androidMain
or
commonMain
. I suspect it has something to do with the single variant approach the Android KMP library plugin uses. I reverted to the plain androidLibrary plugin and they're back. The Render error is: The following classes could not be instantiated: - androidx.compose.ui.tooling.ComposeViewAdapter Has anyone else experienced this?
The suspicion comes from an observation I made when I switch my build variant in a typical android project to any
release
variant. I get a similar render error when this happens. (Since I normally use
debugImplementation
)
t
IIRC the new plugin gets rid of build types; there is no debug/release with the new plugin. If you’re still trying to add the preview dependency using debugImplementation, then it’s trying to add the dependency to a classpath that doesn’t exist. I’d expect some kind of error but maybe it just prints a warning? 🤷🏻 lemme see if I can find the doc about the build variant change.
oh, yea, it’s in the doc you linked: https://developer.android.com/kotlin/multiplatform/plugin#features first bullet point “Single Variant Architecture”
m
Yup. That was the first thing I noticed. But the new plugin doesn't even support any
debugImplementation
or
releaseImplementation
functions. It shows an error if you attempt to write those. And I'm using a plain
implementation
to apply the uiTooling artifact to the androidMain target. It seems like in the process of migrating to a Single variant, preview tooling support got left behind.
Of course, I could be wrong. I'm still trying out various combinations just to make sure. Even if the Compose MP ui tooling isn't working, the standard
androidx.compose.ui:ui-tooling
for the
androidMain
source set should.
I should've done a proper search before asking this. Looks like it's already asked here: https://kotlinlang.slack.com/archives/C3PQML5NU/p1748975773510059
m
Please check workaround described here: https://issuetracker.google.com/issues/422373442, might not work depending on your case but is something to try. At the same time, you can also disable iOS target temporary when using compose previews until issue gets fixed