0Pricing
Kotlin Multiplatform Academy · Lesson

Reading the shared build.gradle.kts

Decode the kotlin{} block and target declarations.

Reading the shared build.gradle.kts is a free Kotlin Multiplatform Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Kotlin Multiplatform Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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.

Frequently asked questions

Is the “Reading the shared build.gradle.kts” lesson free?

Yes — the full text of “Reading the shared build.gradle.kts” is free to read here on the web, and the Kotlin Multiplatform Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Kotlin Multiplatform Academy course, upgrade to CoddyKit PRO.

What will I learn in “Reading the shared build.gradle.kts”?

Decode the kotlin{} block and target declarations. You practise Kotlin Multiplatform Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Kotlin Multiplatform Academy?

No prior experience is required. Kotlin Multiplatform Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Reading the shared build.gradle.kts” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Kotlin Multiplatform Academy lesson?

Yes. Every Kotlin Multiplatform Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. The shared Module vs the App Modules
  2. commonMain, androidMain & iosMain
  3. Reading the shared build.gradle.kts
  4. Where Tests Live: commonTest & Friends
← Back to Kotlin Multiplatform Academy