Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Compose Multiplatform

Status: ⚪ Planned — [compose] enabled = true parses, and source-set discovery already understands composeResources/, but the Compose compiler plugin is not yet applied during a build. See Implementation Status.

Compose Multiplatform is one manifest key:

[compose]
enabled = true

No plugin block, no compiler-plugin coordinate, no version to keep in step with your Kotlin version. Kargo resolves the Compose compiler plugin matching package.kotlin, downloads it, and passes it to the compiler.

Start a project with kargo new my-ui --template cmp.

A full Compose manifest

[package]
name = "my-ui"
group = "com.example"
version = "0.1.0"
kotlin = "2.4.21"

[targets]
jvm = { java-target = "25" }
android = { min-sdk = 24, target-sdk = 36, compile-sdk = 36 }
ios-arm64 = {}
ios-simulator-arm64 = {}

[compose]
enabled = true

[dependencies]
kotlinx-coroutines-core = "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0"

The Compose runtime, UI, foundation, and Material artifacts come in with the plugin. You do not declare them.

Shared UI

// src/commonMain/kotlin/App.kt
package com.example

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier

@Composable
fun App() {
    Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
        Text("Hello from my-ui!")
    }
}

Each platform supplies only its entry point:

// src/jvmMain/kotlin/Main.kt — desktop
fun main() = application {
    Window(onCloseRequest = ::exitApplication, title = "my-ui") { App() }
}
// src/androidMain/kotlin/MainActivity.kt
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent { App() }
    }
}
// src/iosMain/kotlin/MainViewController.kt
fun MainViewController() = ComposeUIViewController { App() }

Resources

Shared images, fonts, and strings live in composeResources/:

src/commonMain/composeResources/
├── drawable/
│   ├── logo.xml
│   └── background.png
├── font/
│   └── Inter-Regular.ttf
└── values/
    └── strings.xml

Kargo generates a typed Res accessor, so a missing resource is a compile error rather than a runtime one:

Image(painterResource(Res.drawable.logo), contentDescription = null)
Text(stringResource(Res.string.app_title))

Platform-specific look and feel

expect/actual covers the places where platforms genuinely differ:

// src/commonMain/kotlin/Theme.kt
@Composable
expect fun PlatformTheme(content: @Composable () -> Unit)
// src/androidMain/kotlin/Theme.kt
@Composable
actual fun PlatformTheme(content: @Composable () -> Unit) {
    MaterialTheme(colorScheme = dynamicColorScheme(LocalContext.current)) { content() }
}

Building and running

kargo run --target jvm                   # desktop window
kargo build --target android
kargo build --target ios-simulator-arm64

For iOS, package a framework and let Xcode consume it:

kargo package --ios-universal

Compose compiler options

Status: ⚪ Planned.

[compose]
enabled = true
strong-skipping = true
metrics = "build/reports/compose"
stability-config = "compose-stability.conf"
KeyPurpose
strong-skippingSkip recomposition more aggressively
metricsEmit recomposition and stability reports
stability-configDeclare third-party classes as stable

The metrics report is the tool for a sluggish UI: it names the composables that recompose when they should not, which is almost always an unstable parameter.

Versions

The Compose compiler plugin is tied to the Kotlin compiler version, and a mismatch produces errors that read like unrelated internal compiler failures. Kargo picks the matching plugin for package.kotlin, so bumping Kotlin bumps Compose with it and there is no second version to forget.

Next