Kotlin Multiplatform shares Kotlin code across platforms while retaining access to native APIs. The best starting point is usually business logic, networking and persistence—not an attempt to share everything.
Practical guidance
- Place portable code in commonMain.
- Use expect/actual sparingly for small platform capabilities.
- Prefer interfaces and dependency injection for larger native integrations.
- Decide separately whether UI will be native or shared with Compose Multiplatform.
Working example
// commonMain
interface DeviceInfo { fun platformName(): String }
class Greeting(private val deviceInfo: DeviceInfo) {
fun text() = "Hello from ${deviceInfo.platformName()}"
}
// androidMain supplies an Android implementation; iosMain supplies an iOS implementation.
Common mistakes
- Shared code can still contain platform assumptions.
- Large expect/actual surfaces are difficult to evolve.
- Adopting KMP without ownership and CI for every target creates hidden risk.
Key takeaway
Adopt one vertical slice, measure reuse and build performance, then expand. Share stable policy while keeping platform-specific experience native where needed.
