Compose Multiplatform aktivieren
Das Plugin und Ihr erstes gemeinsames Composable hinzufügen
Compose Multiplatform aktivieren ist eine kostenlose Kotlin Multiplatform Academy-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Kotlin Multiplatform Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Kotlin Multiplatform Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
One UI, Every Screen
Compose Multiplatform lets you describe your UI once in Kotlin and render it on Android, iOS and desktop. The same screen code runs everywhere. 🎉
Built on Jetpack Compose
If you know Jetpack Compose, you already know most of this. Compose Multiplatform brings that same declarative toolkit to every target you support.
Add the Compose Plugin
You enable it by adding the Compose Gradle plugin alongside the Kotlin Multiplatform plugin in your shared module. That unlocks the composable APIs.
plugins {
kotlin("multiplatform")
id("org.jetbrains.compose")
}Pull In the Compose BOM
The Compose dependencies live behind a single accessor. You add the runtime, foundation and material libraries from the compose extension so versions stay aligned.
kotlin {
sourceSets {
commonMain.dependencies {
implementation(compose.material3)
}
}
}Your First Shared Composable
A composable is just a Kotlin function marked with @Composable. Put it in commonMain and it becomes available to every platform at once.
import androidx.compose.runtime.Composable
import androidx.compose.material3.Text
@Composable
fun Greeting(name: String) {
Text("Hello, " + name)
}A Root App Composable
Most projects expose one top-level App composable in shared code. Each platform simply calls into it, so the whole UI tree is shared.
@Composable
fun App() {
Greeting("KMP")
}Material Theming Comes Along
Compose Multiplatform ships Material components and theming, so buttons, text fields and colors look consistent across platforms out of the box.
@Composable
fun App() {
MaterialTheme {
Greeting("KMP")
}
}Android Hosts It Natively
On Android you mount the shared App inside an Activity using setContent, exactly like a normal Compose app. Nothing special is required.
class MainActivity : ComponentActivity() {
override fun onCreate(b: Bundle?) {
super.onCreate(b)
setContent { App() }
}
}iOS and Desktop Plug In Too
iOS and desktop each have a tiny entry point that hosts the same App composable. You write the screen once and host it from every target.
Live Previews Still Work
You keep fast iteration with @Preview in your IDE, so you see your shared composable render without launching a full device build each time.
What This Unlocks
With Compose enabled, your UI joins your logic in shared code. The result is one codebase driving pixel-identical screens on phones and desktops.
Quick Check
Where does a shared composable belong?
Recap: Compose Everywhere
You enabled the Compose plugin, wrote a shared composable in commonMain, wrapped it in MaterialTheme and saw how each platform hosts the same App. One UI, every screen. 🚀
Häufig gestellte Fragen
Ist die Lektion „Compose Multiplatform aktivieren“ kostenlos?
Ja — der vollständige Text von „Compose Multiplatform aktivieren“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Kotlin Multiplatform Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Kotlin Multiplatform Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Compose Multiplatform aktivieren“?
Das Plugin und Ihr erstes gemeinsames Composable hinzufügen Du übst Kotlin Multiplatform Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Kotlin Multiplatform Academy zu starten?
Keine Vorkenntnisse erforderlich. Kotlin Multiplatform Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.
Wie lange dauert die Lektion „Compose Multiplatform aktivieren“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Kotlin Multiplatform Academy-Lektion Code schreiben und ausführen?
Ja. Jede Kotlin Multiplatform Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Compose Multiplatform aktivieren
- Layouts, Modifier und Theming
- Zustand und Rekombination in der gemeinsamen UI
- Gemeinsame UI auf iOS und Desktop hosten