Very trivial sample to demonstrate being able to use Preview in Android Studio and Fleet, with common icons.
Built to isolate the preview problem because of problems encountered doing the much more complicated Kolapsilist sample.
Summary drama all goes away with Compose Plugin v1.7.0 onwards, no fancy workarounds needed (sigh).
As of 2024-10-11, without having done any abstraction on the image resource, so it's coming from Image(painterResource(Res.drawable.compose_multiplatform)
-
editing in Fleet version: 1.41.101
- previewing App with Android Preview shows the rest of the Column skipping the
Image
without error. (In earlier versions this had a constant out of date - rebuildrenderError
) - previewing App() with Desktop Preview shows the full Column
- previewing App with Android Preview shows the rest of the Column skipping the
-
editing in Android Studio 2024.2.1
- MainActivity.kt supports local Android Preview, working same as Fleet's App() preview showing the
Column
without theImage
.
- MainActivity.kt supports local Android Preview, working same as Fleet's App() preview showing the
I thought I was going to be doing complicated expect/actual
things but it turns out this has been fixed since June
The difference was that I needed to be using an Alpha version of Compose
So the real fix was to edit gradle/libs.versions.toml
and change compose-plugin = "1.7.0-alpha01"
.
- edited
libs.versions.toml
changingcompose-plugin = “1.7.0-alpha01”
- (slow) Gradle resync
- Android preview (from
MainActivity.kt
looked unchanged, not showing image) - Build - Clean Project (possibly unnecessary)
- Ran an Android simulator, which worked (as it had been all along), showing image
- Go back into
MainActivity.kt
and yes the preview now shows the image with a pathRes.drawable.compose_multiplatform
I went around a few hours worth of wasted time, after reading warnings on Slack and testing, found the Android Preview stopped working with 1.7.0-rc01
and 1.7.0
.
Eventually by cross-testing what worked, found that some versions of other libs and build tools need updating between compose-plugin 1.7.0-alpha01
and those later versions.
It is most likely to be something to do with the agp or gradle versions but here's the full list updated, as prompted in Fleet. Do not ignore the yellow underlines
-
libs.versions.toml
- agp 8.2.2 => 8.6.1
- androidx-activityCompose 1.9.2 => 1.9.3
- androidx-lifecycle 2.8.2 => 2.8.3
- kotlin 2.0.20 => 2.0.21 (pretty sure this is irrelevant)
- compose-plutin 1.7.0-alpha01 => 1.7.0
-
gradle-wrapper.properties
- distributionUrl bumped from 8.6 to 8.7
This is a Kotlin Multiplatform project targeting Android, iOS, Web, Desktop.
-
/composeApp
is for code that will be shared across your Compose Multiplatform applications. It contains several subfolders:commonMain
is for code that’s common for all targets.- Other folders are for Kotlin code that will be compiled for only the platform indicated in the folder name.
For example, if you want to use Apple’s CoreCrypto for the iOS part of your Kotlin app,
iosMain
would be the right folder for such calls.
-
/iosApp
contains iOS applications. Even if you’re sharing your UI with Compose Multiplatform, you need this entry point for your iOS app. This is also where you should add SwiftUI code for your project.
Learn more about Kotlin Multiplatform, Compose Multiplatform, Kotlin/Wasm…
We would appreciate your feedback on Compose/Web and Kotlin/Wasm in the public Slack channel #compose-web. If you face any issues, please report them on GitHub.
You can open the web application by running the :composeApp:wasmJsBrowserDevelopmentRun
Gradle task.