< Back to articles

Kotlin Multiplatform in Practice: Sharing Code Between iOS and Android (and What to Avoid)

Kotlin Multiplatform in Practice: Sharing Code Between iOS and Android (and What to Avoid)

📺 Recording of Rostislav Babáček's talk from Ackee Meets: Mobile Development (in Czech):

Kotlin Multiplatform (KMP) promises something like the holy grail of mobile development: write the business logic once and use it natively on both iOS and Android. It sounds great, and it really can be great. But the road there goes through a few unexpected crashes, an evening or two spent arguing with Gradle, and the moment when an iOS developer opens Android Studio for the first time and has no idea where to click. We went through this at Ackee when we brought our previously separate iOS and Android teams together over one shared codebase. Here is an honest overview of the pitfalls and of what really works.

📋 TL;DR

  • Kotlin Multiplatform (KMP) lets you share business logic, the networking layer and data handling between iOS and Android, while the UI stays native.
  • “You just have to plug it in” is a misconception. The platforms don't behave the same, Kotlin hides runtime traps (first() vs. firstOrNull(), a missing @Throws) and exporting to Swift isn't free.
  • The key isn't the technology but people and processes: targeted workshops, time for learning, a monorepo and joint analyses by both platforms.
  • Proven tools: SKIE (a Swift-friendly API generator from Touchlab), Koin (DI), Detekt (static analysis), the Kotlin Native Xcode Plugin (debugging) and git worktree to avoid pointless builds.
  • The payoff of well-adopted KMP: up to about 30% time savings on features with shared ViewModels, consistent app behavior and better interchangeability of developers.
Bugs Bunny and Daffy Duck tugging at a sign with the Apple logo: the rivalry between the iOS and Android camps

🧩 What is Kotlin Multiplatform (KMP)?

Behind the name stands JetBrains, the creators of Kotlin itself. Shared code is written in Kotlin and exported to iOS as a framework, which is then called from Swift. This combination of “shared logic + native look” is the main advantage of KMP over solutions like Flutter or React Native, which share the UI too. Kotlin Multiplatform Mobile went into alpha back in 2020 and the stable version arrived in 2023. Since then, KMP has been a tool that makes sense to use on production client projects.

Goal: make iOS (🍎) behave the same as Android (🤖)

⚖️ When KMP makes sense (and why not Flutter or React Native)

KMP pays off where you want unified business logic across platforms but don't want to give up native UI and performance. You share what should be the same on both platforms (logic, validation, data handling) and keep native what should be platform specific (look, animations, system integrations).

That's why KMP is often the choice even where a pure “one codebase for everything” approach wouldn't fit: you don't share the UI layer, so you don't give up the native look and feel or access to platform APIs. A bonus that is often forgotten: with native UI, accessibility also stays native, so VoiceOver and TalkBack work without workarounds.

Here is KMP side by side with Flutter and React Native:

FeatureKotlin MultiplatformFlutterReact Native
What is sharedbusiness logic (UI stays native)logic and UIlogic and UI
UI layerfully native (SwiftUI / Jetpack Compose)custom rendering (Impeller, formerly Skia)native components via the JS interface (JSI)
Native look and performancepreservedclose to native, but with its own renderergood, with some JS layer overhead
Access to platform APIsdirect and nativethrough pluginsthrough native modules

Meanwhile, another player has entered this map from the opposite direction: the Swift SDK for Android, which tries to bring Swift to Android. So far it's more of an experiment than a production choice, but the direction is worth watching.


🚧 The most common pitfalls when adopting KMP

Moving from “I write for one platform” to “I also write shared Kotlin” has several recurring pitfalls. These are among the most common.

The platforms don't behave the same

Shared logic doesn't mean both platforms behave identically. A nice example is passing data through navigation: Android has a limit on the size of data sent through navigation, while iOS doesn't. A solution that works fine on iOS (passing the object directly) therefore crashes on Android, and you have to store the data elsewhere (say, in a database) and pass only an ID through navigation.

For cases like this it's essential to know the expect/actual mechanism, which lets you have a common interface in shared code and a platform-specific implementation. Without it, you can easily implement an “Android” workaround on iOS too, where you don't need it at all.

Different architecture: MVVM vs. Clean Architecture

iOS apps often rest on MVVM (or TCA), which mainly deals with the relationship between View and ViewModel. The Android world, on the other hand, commonly runs on Clean Architecture, and that naturally carries over into shared KMP code. Clean Architecture is much stricter about the boundaries between layers: suddenly you find out that calling one repository directly from another isn't valid, which MVVM never warned you about. Aligning the architectural habits of both platforms is one of the first tasks to solve.

Hidden runtime traps in Kotlin

“Kotlin looks like Swift, this will be a piece of cake.” Spoiler: it won't. Kotlin has traps that the compiler doesn't reveal when you switch, and that show up only at runtime as a nice crash. The two most common:

1. The behavior of first() on a collection. In Swift, first returns an optional. In Kotlin, first() on an empty collection throws a NoSuchElementException:

list.first() // ⚠️ NoSuchElementException when the collection is empty
list.firstOrNull() // ✅ the safe variant, returns null

2. Unhandled exceptions crossing the boundary into Swift. In Swift, you can tell from the signature that a function throws an error, and the compiler forces you to handle it. In Kotlin, not so. If an interface that can throw an exception lacks the @Throws annotation, the Swift side doesn't know about the exception at all, and the result is a crash:

public interface SetupHeartbeatObserverUseCase {
    @Throws(Throwable::class) // ✅ without this annotation Swift doesn't know an exception may come
    public suspend operator fun invoke()
}

Integration and export to Swift

After export from KMP, the generated APIs aren't naturally Swift-like. When you need to mock something or integrate it nicely, you write a pile of wrappers and mappers around it, and without a well-designed architecture the integration becomes a minor purgatory. (A solution that removes most of this work is the SKIE tool, see the tools section below.)

Development environment and the framework build

An iOS developer used to Xcode runs into the unfamiliar Android Studio, different keyboard shortcuts and Gradle with dozens of tasks (and for a while has no idea where to start). The biggest practical brake, though, is the framework build: with every change in shared KMP code, the framework has to be rebuilt, and that's time you'd rather spend on anything more useful.

Homer Simpson helpless at a control panel with the caption “What do I do?”: how an iOS developer feels after a first encounter with Android Studio and Gradle

Book a consultation

🛠️ How to overcome the pitfalls

Aligning two platforms over one codebase isn't just a question of tools but mostly of people and processes. This is what has worked for us:

  1. Targeted workshops. The more experienced platform runs workshops aimed at specific projects, not general concepts. A developer then easily finds a parallel with the world they know.
  2. Dedicated learning time. Moving to a new technology needs room. At Ackee we have 10% of working time for learning, which gives people a real chance to get better at KMP and Kotlin.
  3. Monorepo. As long as shared code is just a submodule, the team treats it as an external library that doesn't “concern” them. In a monorepo, they see what is happening in the shared layer.
  4. Joint analyses. When designing an integration, always have a representative of both iOS and Android. The goal is a compromise, not one platform dictating a solution that the other will integrate through tears.
  5. Accepting reality. The team and project management have to count on it taking longer at first. The payoff comes with time.

Babáček sums it up like this:

“A feature that I'd write natively in two hours can easily take me six in KMP at the beginning. But you have to push through it, and over time it improves dramatically.”

Rostislav Babáček, Team Leader of the Indigo Mobile Development team and lead implementer of Agentic Development at Ackee

Tools that make the transition easier

  • SKIE (from Touchlab) is a generator of Swift-friendly APIs on top of KMP. It lets you comfortably observe the state of a KMP ViewModel from Swift without hand-written wrappers.
  • Koin is dependency injection for shared code.
  • Detekt is static analysis that can cover a number of runtime traps (for example, enforcing @Throws). Deterministic lint rules catch an error before it turns into a crash in production.
  • Kotlin Native Xcode Plugin (from Touchlab) gives you breakpoints directly in KMP code and a view of the stack trace and variable values, instead of endlessly adding prints and rebuilding.
  • git worktree is a side clone of the repository for quick incident firefighting. You build the framework once, and when you return to the original branch you skip another build.
💡
The biggest improvement: move ViewModels to KMP

The more logic (including ViewModels) you move into shared code, the less of it is left on the platform. Behavior becomes consistent and you make fixes in one place, not two. With SKIE, the hand-written wrappers around KMP ViewModels go away too.

🤖 Agentic development in a KMP monorepo

A monorepo with shared code works well with AI-assisted development. These things have proven useful:

  • Scoped rules. The agent doesn't load Android/KMP rules into its context when you're working only on the iOS part (and vice versa).
  • Skills for recurring integration tasks, such as creating a new KMP screen with Koin registration, or wiring a use case into an existing ViewModel without writing boilerplate by hand.
  • A review agent for runtime errors, as a complement to deterministic lint rules, not a replacement.

Orchestrating multiple agents is still debatable. It isn't yet fully clear whether it helps the agent or rather confuses it.


👥 Organizational impact: from platform teams to project teams

Sharing code has an organizational side too. When iOS and Android developers work on the same logic, it stops making sense to split teams by platform. At Ackee we therefore moved from separate iOS and Android teams to project-focused mobile teams: each team is a mix of both platforms, shares know-how and project context, and the platform worlds gradually grow closer. On top of that, a regular joint all-hands with technology news helps.

The result is better interchangeability: when an incident comes, any mobile developer can handle it, not just “the one for that platform”.

Two excitedly clapping children: joy that platform teams have become collaborating mobile teams

📈 What the results are

Well-adopted KMP brings measurable as well as “soft” benefits:

  • Up to about 30% time savings (an internal estimate from our projects, not a measurement) on features where the logic (including ViewModels) is in shared code.
  • Consistent behavior of the apps: both platforms behave the same, which QA and the client both appreciate.
  • Better interchangeability of developers and less duplicated logic that would otherwise have to be fixed in two places.
⚠️
Take the 30% with a grain of salt

The savings aren't universal. On some features you save nothing, on others it's a few percent, and until the logic (for example ViewModels) is in shared code, the benefit can be zero or even negative. Good design and honest analysis make the difference.

Frequently asked questions

A technology from JetBrains for sharing code (business logic, networking layer, data handling) between iOS and Android while keeping native UI on each platform.
KMP shares only business logic, and the UI stays native. Flutter and React Native share the UI layer too. That's why KMP is chosen by teams that don't want to give up native look and performance.
Kotlin's first() on an empty collection throws a NoSuchElementException. Use firstOrNull(), which returns null.
Without it, the Swift side doesn't know that a shared function can throw an exception, and a runtime crash follows. @Throws makes the exception “visible” for Swift interoperability.
On features with shared ViewModels, up to about 30% in practice. The savings depend on the design, though; on some features they are minimal or none.
SKIE (a Swift-friendly API generator), Koin (DI), Detekt (static analysis), the Kotlin Native Xcode Plugin (debugging) and git worktree (faster work with builds).

🎯 Key takeaways

Sharing code between iOS and Android through Kotlin Multiplatform isn't just a technical “plug-in”. It is both a technological and an organizational change, built on both platforms' willingness to align their architecture, analyze honestly and accept that the payoff comes gradually. If you get through it, the result is consistent apps, interchangeable developers and a mobile team that pulls together, even if you sweat over the first crashes.

Subscribe to the newsletter

What this transition looks like on a running project that is several years old is described in the follow-up article on the migration of a banking app to KMP. You can find the whole story, including the audience discussion, in the talk recording (in Czech). Watch for dates of future Ackee Meets on Eventbrite and subscribe to the newsletter (in Czech) so the next piece like this lands straight in your inbox.

Rostislav Babáček
Rostislav Babáček
Team Leader, Indigo Mobile Development team

Are you interested in working together? Let’s discuss it in person!