Compose UI previews
You can create preview composables to see your UI rendered in the IDE (IntelliJ IDEA and Android Studio) without running an emulator. Previews are a part of core functionality of Jetpack Compose.
Compose Multiplatform initially implemented a limited @Preview annotation as a custom library, but starting with version 1.10.0, this implementation has been deprecated as the original AndroidX annotation is now fully multiplatform.
On this page, you can find:
how to enable previews in common code for different project configurations,
overview of supported combinations of Compose Multiplatform, AGP, and annotations.
Preview setup
To enable preview support in your IDE, add the necessary dependencies to the build.gradle.kts file of your KMP module:
The annotation dependency for the
commonMainsource set: the old or the new one, depending on the Compose Multiplatform version.The tooling dependency on the classpath, whose declaration depends on the Android configuration.
The annotation dependency should point to one of the @Preview implementations, for example:
The tooling dependency should be declared in the root dependencies {} block of the build.gradle.kts file in your KMP module in one of two ways, depending on your Android target configuration:
If you're using the
com.android.applicationorcom.android.libraryplugin:dependencies { debugImplementation("org.jetbrains.compose.ui:ui-tooling:1.10.0") }If you're using the
com.android.kotlin.multiplatform.libraryplugin:dependencies { androidRuntimeClasspath("org.jetbrains.compose.ui:ui-tooling:1.10.0") }
Supported configurations
Depending on the version of your dependencies and the configuration style of your project, there are several supported combinations that you can use to enable Compose previews:
Compose Multiplatform 1.9, with the old
@Previewannotation and Android configured withandroidTarget {}.Compose Multiplatform 1.10, with the old
@Previewannotation and Android configured withandroidTarget {}.Compose Multiplatform 1.10, with the new
@Previewannotation and Android configured withandroidTarget {}.Compose Multiplatform 1.10, with the new
@Previewannotation and Android configured withandroidLibrary {}with AGP 9.0. See our AGP 9.0 migration guide for details on upgrading your KMP apps.
Available annotations
There are two @Preview annotations available in Compose Multiplatform:
androidx.compose.ui.tooling.preview.PreviewThis is the original Android Jetpack annotation, made multiplatform with Compose Multiplatform 1.10. It supports all parameters from the Android declaration in common code.
The necessary runtime dependency is
org.jetbrains.compose.ui:ui-tooling-preview.This is the recommended annotation to use going forward.
org.jetbrains.compose.ui.tooling.preview.PreviewThis was the first multiplatform implementation of the annotation, emulating the Android-only experience. It supports a limited number of parameters, but provides basic preview functionality.
The necessary runtime dependency is
org.jetbrains.compose.components:components-ui-tooling-preview.This annotation is now deprecated in Compose Multiplatform 1.10.
To use one of these annotations in your shared code, add the appropriate runtime dependency for your commonMain source set, as shown above.
Android target configurations
If your project uses Android Gradle plugin 8.x, the Kotlin Multiplatform part of the project should use either the Android application (com.android.application) or the Android library (com.android.library) plugin, and the Android configuration is contained in the androidTarget {} block of your build.gradle.kts file.
For Android Gradle plugin 9.0, there is a new KMP Android library plugin (com.android.kotlin.multiplatform.library) which introduces the androidLibrary {} block for Android configuration. While it's also possible to use this plugin with AGP 8.x, that combination has known issues and is not recommended.
For details on upgrading to AGP 9.0, see our migration page.