zsmb.co



Setting up Compose Multiplatform previews

2025-07-29 • Márton Braun

Earlier this year, the new Kotlin Multiplatform IDE plugin was released, with one of the highlighted features being Compose previews for common code, powered by the Android preview tooling. In this blog post, we’ll look at how to set this up in your projects.

As the first step, install the Kotlin Multiplatform IDE plugin. It’s available for both IntelliJ IDEA and Android Studio. When in doubt about versions, use the latest stable release of your IDE of choice.

The plugin is available for macOS at the moment. If you’re on Windows or Linux, take a look at this section below.

We’ll first take a look at how you can create a new project with the KMP wizard that’s already configured correctly, and then we’ll see how you can add previews to an existing project.

Using the wizard

The easiest way to get a project that has working previews is to create a new project with the wizard. This is available on the web but also as part of the IDE tooling now.

  • In IntelliJ IDEA, go to File > New > Project, and pick the Kotlin Multiplatform generator.

    TODO
  • In Android Studio, go to File > New > New Project, and choose the Kotlin Multiplatform template (you’ll have to scroll down to find it).

    TODO

Make sure that the project you create includes an Android target, as common previews are based on the Android preview system, and won’t be available without an Android target configured.

After the project opens, go to App.kt which already has the App function annotated with @Preview. You should see a split view available (toggle in the top right if it doesn’t open as the split view immediately), where the preview is rendered on the right:

TODO

Features like interactive previews or copying the preview as an image are also available, like on Android:

Setting up previews in an existing project

If you have an existing Compose Multiplatform project, you can follow these steps below to get set up. (You can also just copy this configuration from a freshly-generated wizard project, if that’s easier.)

  1. Make sure that you have an Android target in your module.

  2. Add the uiToolingPreview dependency to commonMain:

    kotlin {
        sourceSets {
            commonMain.dependencies {
                implementation(compose.components.uiToolingPreview)
            }
        }
    }
    
  3. Add the compose.uiTooling dependency to your Android debug builds:

    dependencies {
        debugImplementation(compose.uiTooling)
    }
    
  4. Create a Composable function with the @Preview annotation in the commonMain source set:

    import org.jetbrains.compose.ui.tooling.preview.Preview
    
    @Preview
    @Composable
    fun HelloWorld() {
        Text("Hello world!")
    }
    

Windows and Linux users

At the time of writing this, the Kotlin Multiplatform IDE plugin is only available for macOS, but that doesn’t mean that you don’t get previews on Windows or Linux!

To get a very comparable setup to what the KMP plugin gives you on macOS, install these plugins:

These, among other features, will also provide the same preview experience as described above.

This section should be invalidated in the near future as Windows and Linux support in the IDE plugin is coming soon.


Follow me to keep in touch and get notified of similar posts!

You might also like...

Sealed goodies coming in Kotlin 1.5

Kotlin 1.5 will bring exciting new features, among them improvements to sealed classes and an introduction of sealed interfaces. Let's take a look at what that will look like!

Retrofit meets coroutines

Retrofit's coroutine support has been a long time coming, and it's finally coming to completion. Take a look at how you can use it to neatly integrate networking into an application built with coroutines.

How I Finally Memorized Modifier Ordering in Compose

For the longest time, I proudly had no idea of how Modifier ordering works, and would just guess and then guess again when something didn't look quite right. Here's how I finally ended up remembering how the ordering works.

Compose O'Clock

I started learning Jetpack Compose this week. Two days into that adventure, here's a quick look at how a neat clock design can be built up in Compose, step-by-step.


Built with Hugo. Hosted on Netlify. Icons by Font Awesome.