0Pricing
Kotlin Multiplatform Academy · レッスン

Compose Multiplatformを有効にする

pluginと最初の共有composableを追加します

「Compose Multiplatformを有効にする」はCoddyKit上の無料Kotlin Multiplatform Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはKotlin Multiplatform Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Kotlin Multiplatform Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

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. 🚀

よくある質問

「Compose Multiplatformを有効にする」レッスンは無料ですか?

はい。「Compose Multiplatformを有効にする」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Kotlin Multiplatform Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Kotlin Multiplatform Academyコースには全4レッスンが含まれています。

「Compose Multiplatformを有効にする」で何を学びますか?

pluginと最初の共有composableを追加します ブラウザで直接実行するハンズオンコードでKotlin Multiplatform Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Kotlin Multiplatform Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのKotlin Multiplatform Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。

「Compose Multiplatformを有効にする」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このKotlin Multiplatform Academyレッスンでコードを書いて実行できますか?

はい。すべてのKotlin Multiplatform Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. Compose Multiplatformを有効にする
  2. Layouts、Modifiers、Theming
  3. 共有UIのStateとRecomposition
  4. iOSとDesktopで共有UIをホストする
← Kotlin Multiplatform Academyに戻る