0Pricing
Kotlin Academy · Lesson

KMM Project Structure

Shared and platform code.

KMM Project Structure is a free Kotlin Academy lesson on CoddyKit — lesson 1 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 Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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.

Frequently asked questions

Is the “KMM Project Structure” lesson free?

Yes — the full text of “KMM Project Structure” is free to read here on the web, and the Kotlin 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 Academy course, upgrade to CoddyKit PRO.

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; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

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