DEV Community

Cameron Hayden
Cameron Hayden

Posted on

KMP on a real app: the first shared module

We just shipped our first Kotlin Multiplatform module in a real app. It's small — models, validation, and a bit of networking — but it's in production.

What I'd tell someone starting:

  • Start with a module that has no UI dependencies
  • Write the tests in shared code from day one
  • Keep platform-specific code behind interfaces, not expect/actual everywhere

The biggest win was validation: one implementation, same behavior on both platforms, one place to fix bugs.

The biggest surprise was build times. They're noticeable, and they add up in CI.

Next step is sharing some state-management logic. I'm being cautious about that one — UI-adjacent code is where shared modules get messy.

Top comments (3)

Collapse
 
abhi_dunna profile image
Abhinav Dunna •

The point about build times adding up in CI is interesting, especially when the shared module is still relatively small. The benefit of having one validation implementation across both platforms makes a lot of sense, but I can see how the feedback loop could get slower as the project grows.

I'm curious: have you found a way to keep development fast while still getting the benefits of shared tests? For example, do you run common-module tests separately during development and save the full multiplatform build for CI, or has that not been necessary yet?

Also interested in how you decide which state-management logic is safe to share versus what should stay platform-specific. That boundary seems like it could make or break the maintainability of a KMP project.

Collapse
 
hayden_86 profile image
Cameron Hayden •

We haven't split the build yet, and I already regret it a little. Right now CI runs ./gradlew :shared:allTests and locally I just run the JVM test task while iterating. That one split helps, but the iOS side still costs a few minutes per run. The next thing I want to try is exactly what you said: common tests on the JVM target in a pre-commit hook, full multiplatform build only in CI. Not sure that'll hold once the module grows.

On state management, our rule so far is crude: if it needs UI framework types (Compose/SwiftUI) or platform lifecycle, it stays out of shared. What we do share is pure state transitions — validation, reducers, the state machine itself — with effects behind interfaces. That worked for models and validation because they're pure functions.

We haven't moved state management yet, and honestly the boundary still feels fuzzy for us. The part I'm most worried about is state that looks shareable but depends on platform timing, like app lifecycle or background tasks. That's where I'd expect shared code to get messy. So the plan is to share the state machine but keep the view models platform-specific for one release, and see how it feels.

Collapse
 
abhi_dunna profile image
Abhinav Dunna •

Thanks for the detailed answer, Cameron. Sharing the state machine and keeping view models platform-specific for one release sounds like a good way to test the boundary without committing to it. I’d be curious to hear what you learn from it, especially whether the iOS build time stays manageable as the module grows.