Kotlin Academy · Lesson

KMM Project Structure

Shared and platform code.

Lesson 1 of 413 steps

KMM Project Structure is a free Kotlin Academy lesson on CoddyKit. This is lesson 1 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Kotlin Academy learning path, and your progress syncs across the web and the CoddyKit app. The Kotlin Academy course includes 4 lessons in total.

What is KMM?

Kotlin Multiplatform Mobile (KMM) lets you share code between iOS and Android while keeping native UIs. You write business logic once in Kotlin.

The shared Module

A KMM project centers on a shared module. It compiles to a JVM library for Android and a native framework for iOS.

  • Android consumes it as a regular dependency
  • iOS imports it as an Objective-C/Swift framework

Source Sets

The shared module is split into source sets:

  • commonMain — shared, platform-agnostic code
  • androidMain — Android-specific code
  • iosMain — iOS-specific code

commonMain

commonMain can only use Kotlin standard library and multiplatform libraries. It must not reference Android or iOS APIs directly.

// shared/src/commonMain/kotlin/Greeting.kt
class Greeting {
    fun greet(): String = "Hello, KMM!"
}

Configuring Targets

The shared build.gradle.kts declares which platforms to build with the multiplatform plugin.

kotlin {
    androidTarget()
    iosX64()
    iosArm64()
    iosSimulatorArm64()
}

The iOS Framework

The iOS targets are bundled into a single framework that Xcode imports.

kotlin {
    listOf(iosX64(), iosArm64(), iosSimulatorArm64()).forEach {
        it.binaries.framework {
            baseName = "Shared"
        }
    }
}

Common Dependencies

Multiplatform libraries (coroutines, serialization, Ktor) go into commonMain so every target shares them.

sourceSets {
    val commonMain by getting {
        dependencies {
            implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1")
        }
    }
}

Android App Module

The Android app module depends on shared like any Gradle module and builds the Android UI with Jetpack Compose or Views.

// androidApp/build.gradle.kts
dependencies {
    implementation(project(":shared"))
}

iOS App

The iOS app is a standard Xcode project. It links the generated Shared framework and calls Kotlin classes from Swift.

// Swift
// import Shared
// let text = Greeting().greet()

What to Share

Typical shared code: networking, data models, repositories, use-cases, validation. Keep UI, navigation, and platform sensors native.

A Self-Contained Greeting

The shared logic is plain Kotlin. Here is the same class running standalone to show it is ordinary code.

class Greeting {
    fun greet(): String = "Hello, KMM!"
}

fun main() {
    println(Greeting().greet())
}

Quick Check

Where do you put code that must be free of any Android or iOS API references?

Recap

You learned KMM structure:

  • A shared module with commonMain, androidMain, iosMain
  • Targets declared in the multiplatform plugin; iOS gets a framework
  • Android depends via project(":shared"); iOS imports the framework

Next: expect and actual.

Free to start

Learn Kotlin with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
51
Lessons
203

Frequently Asked Questions

Is the “KMM Project Structure” lesson free?

Yes — any 3 lessons of the Kotlin Academy learning path, including “KMM Project Structure”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Kotlin Academy course includes 4 lessons in total.

What will I learn in “KMM Project Structure”?

Shared and platform code. You practise Kotlin 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 Academy?

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

How long does the “KMM Project Structure” 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 Academy lesson?

Yes. Every Kotlin 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. KMM Project Structure
  2. expect and actual
  3. Sharing Business Logic
  4. Platform APIs
← Back to Kotlin Academy