Kotlin Multiplatform Development Help

Updating Compose compiler

The Compose compiler is supplemented by a Gradle plugin, which simplifies setup and offers easier access to compiler options. When applied with the Android Gradle plugin (AGP), this Compose compiler plugin will override the coordinates of the Compose compiler supplied automatically by AGP.

The Compose compiler has been merged into the Kotlin repository since Kotlin 2.0.0. This helps smooth the migration of your projects to Kotlin 2.0.0 and later, as the Compose compiler ships simultaneously with Kotlin and will always be compatible with Kotlin of the same version.

To use the new Compose compiler plugin in your project, apply it for each module that uses Compose. Read on for details on how to migrate a Compose Multiplatform project. For a Jetpack Compose project, refer to the migration guide.

Migrating a Compose Multiplatform project

Starting with Compose Multiplatform 1.6.10, you should apply the org.jetbrains.kotlin.plugin.compose Gradle plugin to each module that uses the org.jetbrains.compose plugin:

  1. Add the Compose compiler Gradle plugin to the Gradle version catalog:

[versions] # ... kotlin = "2.0.0" [plugins] # ... jetbrainsCompose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" } kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
  1. Add the Gradle plugin to the root build.gradle.kts file:

plugins { // ... alias(libs.plugins.jetbrainsCompose) apply false alias(libs.plugins.compose.compiler) apply false }
  1. Apply the plugin to every module that uses Compose Multiplatform:

plugins { // ... alias(libs.plugins.jetbrainsCompose) alias(libs.plugins.compose.compiler) }
  1. If you are using compiler options for the Jetpack Compose compiler, set them in the composeCompiler {} block. See Compose compiler options DSL for reference.

Possible issue: "Missing resource with path"

When switching from Kotlin 1.9.0 to 2.0.0, or from 2.0.0 to 1.9.0, you may encounter the following error:

org.jetbrains.compose.resources.MissingResourceException: Missing resource with path: ...

To resolve this, delete all the build directories: at the root of your project and in each of the modules.

What's next

Last modified: 06 November 2024