0Pricing
Kotlin Multiplatform Academy · レッスン

共有build.gradle.ktsを読む

kotlin{}ブロックとターゲット宣言を読み解きます

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

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

The Module's Recipe

The shared build.gradle.kts is the recipe for your module: which targets to build and which libraries to pull in.

Plugins Come First

At the top, the plugins block turns on multiplatform support. Without it, Kotlin has no idea about targets.

plugins {
    kotlin("multiplatform")
    id("com.android.library")
}

The kotlin {} Block

Everything multiplatform lives inside the kotlin block. This is where targets and source sets are declared.

kotlin {
    // targets and source sets go here
}

Declaring Android

The androidTarget line tells Kotlin to produce an Android library artifact from your shared code.

kotlin {
    androidTarget()
}

Declaring iOS

iOS needs a few targets, one per architecture, so it runs on simulators and real devices alike.

iosX64()
iosArm64()
iosSimulatorArm64()

Naming the Framework

A binaries.framework entry names the iOS framework Swift will import. Pick a clean name your iOS team will type often.

iosArm64 {
    binaries.framework {
        baseName = "Shared"
    }
}

Source Set Dependencies

The sourceSets block lists libraries per set. commonMain gets cross-platform deps; platform sets get their own.

sourceSets {
    commonMain.dependencies {
        // shared libraries
    }
}

Common Dependencies Are Shared

A library added to commonMain must support every target. Add it here and all platforms can use it.

commonMain.dependencies {
    implementation("io.ktor:ktor-client-core:2.3.0")
}

Platform Dependencies

Platform-only libraries go in their own set, like an Android engine that only the JVM target understands.

androidMain.dependencies {
    implementation("io.ktor:ktor-client-okhttp:2.3.0")
}

Android Config Block

A separate android block sets the namespace and SDK levels for the Android library half of the module.

android {
    namespace = "com.example.shared"
    compileSdk = 34
}

Read It Top to Bottom

To grok any shared build file, read it as a story: plugins, then targets, then source sets, then platform config. 📖

Quick Check

Where does a cross-platform library belong?

Recap

The shared build.gradle.kts flows plugins to targets to source sets. Common deps for all, platform deps for one.

よくある質問

「共有build.gradle.ktsを読む」レッスンは無料ですか?

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

「共有build.gradle.ktsを読む」で何を学びますか?

kotlin{}ブロックとターゲット宣言を読み解きます ブラウザで直接実行するハンズオンコードでKotlin Multiplatform Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

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

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

「共有build.gradle.ktsを読む」レッスンにはどのくらい時間がかかりますか?

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

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

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

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

  1. shared ModuleとApp Modules
  2. commonMain、androidMain、iosMain
  3. 共有build.gradle.ktsを読む
  4. テストはどこにあるか:commonTestと仲間たち
← Kotlin Multiplatform Academyに戻る