DEV Community

Cover image for Kotlin Multiplatform in 2026: Complete Guide with Real-World Architecture, Kotlin Examples & Interview Questions
Padmakar Garg
Padmakar Garg

Posted on

Kotlin Multiplatform in 2026: Complete Guide with Real-World Architecture, Kotlin Examples & Interview Questions

If you are an Android developer, you probably know Kotlin, Jetpack Compose, MVVM, Coroutines, Retrofit, Room, and modern Android architecture.

But what if you need to build the same product for Android and iOS?

Traditionally, teams maintain separate implementations:

  • Kotlin for Android.
  • Swift for iOS.
  • Separate networking and data layers.
  • Separate business rules and validation.
  • Separate database and synchronization logic.

This can lead to duplicated effort and inconsistent behavior. Kotlin Multiplatform (KMP) offers another approach: share suitable Kotlin code across platforms while retaining native capabilities and, when desired, native user interfaces.

This guide explains KMP from an Android developer's perspective, with architecture examples, Kotlin snippets, production considerations, real-world scenarios, and interview questions.

1. What is Kotlin Multiplatform?

Kotlin Multiplatform is a technology for sharing Kotlin code across multiple platforms, including Android, iOS, desktop, and other supported targets.

You can share:

  • Business rules and use cases.
  • Networking and serialization.
  • Repository implementations.
  • Database access.
  • Validation and data mapping.
  • Authentication workflows.
  • Offline synchronization logic.

You can still write Android UI with Jetpack Compose and iOS UI with SwiftUI.

The key idea: share code where it makes sense, and keep platform-specific code where it is needed.

2. KMP vs Compose Multiplatform

These terms are related, but they are not interchangeable.

Kotlin Multiplatform (KMP) provides the technology and project model for sharing Kotlin code across targets. It does not require sharing UI.

Compose Multiplatform is a declarative UI framework that lets you share UI code across supported platforms.

Two common approaches are:

Option A: Shared business logic, native UI

Android app                         iOS app
Jetpack Compose                     SwiftUI
      |                                |
      +---------------+----------------+
                      |
                Shared KMP
          Domain / Data / Networking
                      |
                API and Database
Enter fullscreen mode Exit fullscreen mode

This approach is useful when an existing product already has native Android and iOS applications, or when each platform needs a distinct native experience.

Option B: Shared UI and business logic

Android app                         iOS app
      |                                |
      +---------------+----------------+
                      |
             Compose Multiplatform
                      |
               Shared KMP logic
                      |
                API and Database
Enter fullscreen mode Exit fullscreen mode

This can reduce duplicated UI work when a shared design and interaction model is appropriate.

Area KMP Compose Multiplatform
Shared business logic Yes Can use KMP
Shared networking Yes Can use KMP
Shared database logic Yes Can use KMP
Shared UI Not required Yes
Native UI possible Yes Yes, through platform integration

Interview point: KMP is about sharing Kotlin code. Compose Multiplatform is an option for sharing UI on top of the multiplatform ecosystem.

3. KMP vs Flutter vs React Native

Feature Kotlin Multiplatform Flutter React Native
Primary language Kotlin Dart JavaScript / TypeScript
Native UI option Yes Platform integration Yes
Shared UI With Compose Multiplatform Flutter widgets React Native components
Existing native app integration Incremental sharing is a core use case Possible Possible
Business logic sharing Yes Yes Yes

There is no universally best framework. Choose based on team skills, existing applications, product requirements, UI requirements, platform integrations, and long-term maintenance.

4. Recommended KMP Architecture

A practical production architecture can use Presentation, Domain, Data, and Platform Integration boundaries.

                Android app                 iOS app
              Jetpack Compose              SwiftUI
                    |                         |
                    +-----------+-------------+
                                |
                         Shared KMP code
                                |
              +-----------------+-----------------+
              |                 |                 |
         Presentation         Domain             Data
              |                 |                 |
         UI state          Use cases          Repositories
                                |                 |
                           Business rules     +---+------+
                                              |          |
                                            Ktor      SQLDelight
                                              |          |
                                              +----+-----+
                                                   |
                                             Platform APIs
Enter fullscreen mode Exit fullscreen mode

Presentation layer

Responsible for screen state and user interaction. Depending on the project, presentation may be native on each platform or shared using Compose Multiplatform.

Domain layer

Contains business rules, entities, repository contracts, and use cases.

Examples:

  • LoginUserUseCase
  • GetUserProfileUseCase
  • CreateTaskUseCase
  • ValidateEmailUseCase
  • SyncPendingTasksUseCase

Keep this layer independent of Android and iOS UI frameworks.

Data layer

Implements repository contracts and handles remote and local data sources, mapping, caching, and synchronization.

Platform integration layer

Provides platform-specific capabilities such as secure storage, camera access, biometrics, push notifications, and file selection.

5. Suggested Project Structure

For a starter project with a shared module and Compose application module:

MyKmpApplication/
|
+-- composeApp/
|   +-- src/
|       +-- commonMain/
|       +-- androidMain/
|       +-- iosMain/
|
+-- shared/
|   +-- src/
|       +-- commonMain/
|       |   +-- kotlin/
|       |       +-- domain/
|       |       |   +-- model/
|       |       |   +-- repository/
|       |       |   +-- usecase/
|       |       +-- data/
|       |       |   +-- remote/
|       |       |   +-- local/
|       |       |   +-- repository/
|       |       |   +-- mapper/
|       |       +-- di/
|       |       +-- utils/
|       |
|       +-- commonTest/
|       +-- androidMain/
|       +-- iosMain/
|
+-- iosApp/
    +-- App.swift
    +-- ContentView.swift
Enter fullscreen mode Exit fullscreen mode

The exact template and source-set hierarchy depend on the Kotlin Gradle plugin version and configured targets.

Important source sets

Source set Purpose
commonMain Shared production Kotlin code
commonTest Shared tests
androidMain Android-specific implementation
androidUnitTest Android unit tests
iosMain iOS-target implementation
iosTest iOS tests

6. expect and actual

Sometimes shared code needs functionality that differs by platform. Kotlin provides expect and actual declarations for this purpose.

For example, imagine that you need the device name.

Common declaration

// commonMain
expect class DeviceInfo() {
    fun getDeviceName(): String
}
Enter fullscreen mode Exit fullscreen mode

Android implementation

// androidMain
import android.os.Build

actual class DeviceInfo actual constructor() {
    actual fun getDeviceName(): String {
        return "${Build.MANUFACTURER} ${Build.MODEL}"
    }
}
Enter fullscreen mode Exit fullscreen mode

iOS implementation

// iosMain
import platform.UIKit.UIDevice

actual class DeviceInfo actual constructor() {
    actual fun getDeviceName(): String {
        return UIDevice.currentDevice.name
    }
}
Enter fullscreen mode Exit fullscreen mode

Shared code can now depend on the common declaration:

class GetDeviceNameUseCase(
    private val deviceInfo: DeviceInfo
) {
    operator fun invoke(): String = deviceInfo.getDeviceName()
}
Enter fullscreen mode Exit fullscreen mode

Use expect/actual when a platform-specific API genuinely needs a platform-specific implementation. For larger services, an interface plus dependency injection can offer a more flexible boundary.

7. Networking with Ktor Client

Ktor Client lets you write shared HTTP client and API code in Kotlin.

Data model

import kotlinx.serialization.Serializable

@Serializable
data class UserDto(
    val id: Int,
    val name: String,
    val email: String
)
Enter fullscreen mode Exit fullscreen mode

Create the client

fun createHttpClient(engine: HttpClientEngine): HttpClient =
    HttpClient(engine) {
        install(ContentNegotiation) {
            json(
                Json {
                    ignoreUnknownKeys = true
                    isLenient = true
                }
            )
        }

        expectSuccess = true
    }
Enter fullscreen mode Exit fullscreen mode

API service

class UserApi(
    private val client: HttpClient
) {
    suspend fun getUsers(): List<UserDto> =
        client.get("https://api.example.com/users").body()
}
Enter fullscreen mode Exit fullscreen mode

Repository contract and implementation

interface UserRepository {
    suspend fun getUsers(): Result<List<UserDto>>
}

class UserRepositoryImpl(
    private val api: UserApi
) : UserRepository {
    override suspend fun getUsers(): Result<List<UserDto>> =
        runCatching { api.getUsers() }
}
Enter fullscreen mode Exit fullscreen mode

Use case

class GetUsersUseCase(
    private val repository: UserRepository
) {
    suspend operator fun invoke() = repository.getUsers()
}
Enter fullscreen mode Exit fullscreen mode

Ktor uses a platform-appropriate HTTP engine. Common choices include OkHttp or Android on Android, and Darwin on Apple platforms.

Production networking should also consider:

  • Connection and request timeouts.
  • Authentication and token refresh.
  • Structured error mapping.
  • Cancellation.
  • Retry policy and idempotency.
  • Serialization failures.
  • Secure transport and certificate validation.
  • Safe logging that never exposes credentials or sensitive data.

8. Dependency Injection with Koin

Koin is a Kotlin-first dependency injection framework commonly used in KMP applications.

A simplified shared module:

val sharedModule = module {
    single { UserApi(get()) }

    single<UserRepository> {
        UserRepositoryImpl(get())
    }

    factory {
        GetUsersUseCase(get())
    }
}
Enter fullscreen mode Exit fullscreen mode

Provide the HTTP engine from each platform:

// androidMain
val androidModule = module {
    single<HttpClientEngine> {
        OkHttp.create()
    }
}
Enter fullscreen mode Exit fullscreen mode
// iosMain
val iosModule = module {
    single<HttpClientEngine> {
        Darwin.create()
    }
}
Enter fullscreen mode Exit fullscreen mode

Initialize Koin with the common and platform modules during application startup. The exact startup integration depends on whether the UI is native or shared.

Why use dependency injection?

  • Dependencies are explicit.
  • Implementations can be replaced in tests.
  • Platform-specific implementations can be supplied at the platform boundary.
  • Object creation is centralized.
  • Modules can be organized by feature.

Koin is not the only option. Choose a DI approach that fits the project's scale and team experience.

9. Database with SQLDelight

SQLDelight generates type-safe Kotlin APIs from SQL statements and supports multiplatform database drivers.

Example schema:

CREATE TABLE TaskEntity (
    id TEXT NOT NULL PRIMARY KEY,
    title TEXT NOT NULL,
    description TEXT,
    is_completed INTEGER AS Boolean NOT NULL DEFAULT 0
);

selectAllTasks:
SELECT * FROM TaskEntity;

insertTask:
INSERT OR REPLACE INTO TaskEntity(
    id,
    title,
    description,
    is_completed
)
VALUES (?, ?, ?, ?);
Enter fullscreen mode Exit fullscreen mode

A simplified data source:

class TaskLocalDataSource(
    private val database: AppDatabase
) {
    fun getTasks() =
        database.taskQueries.selectAllTasks()

    fun insertTask(
        id: String,
        title: String,
        description: String?,
        isCompleted: Boolean
    ) {
        database.taskQueries.insertTask(
            id,
            title,
            description,
            isCompleted
        )
    }
}
Enter fullscreen mode Exit fullscreen mode

The generated query API depends on the SQLDelight schema and configuration.

For production, also consider migrations, indexes, transactions, database driver setup, and test databases.

10. Offline-First Architecture

Offline-first behavior is a valuable real-world KMP use case.

Imagine an employee creates a task while working in an area with no internet connection.

A robust application should not force the user to wait for the server before seeing the task.

User creates task
       |
       v
Repository
       |
       v
Local database
       |
       +------> UI observes local data
       |
       v
Pending sync operation
       |
       v
Network becomes available
       |
       v
Remote API
       |
       v
Conflict / response handling
       |
       v
Update local database
Enter fullscreen mode Exit fullscreen mode

A practical synchronization strategy:

  1. Save the change locally.
  2. Display the local result immediately.
  3. Record a pending operation with a unique ID.
  4. Attempt synchronization when appropriate.
  5. Retry transient failures with bounded backoff.
  6. Make server operations idempotent where possible.
  7. Resolve conflicts using an explicit product policy.
  8. Update local synchronization status.

Real-world problem: Duplicate requests

A user taps Create twice because the network is slow. The client may submit two requests.

Possible protections:

  • Disable or debounce repeated UI actions where appropriate.
  • Assign a unique operation ID.
  • Use backend idempotency keys.
  • Track pending operations.
  • Make retry behavior safe.

Network availability does not guarantee that a request will succeed.

11. Android and iOS Interoperability

Android can consume shared Kotlin classes through the shared module.

class Greeting {
    fun greet(): String = "Hello from shared Kotlin"
}
Enter fullscreen mode Exit fullscreen mode

Android usage:

val greeting = Greeting()
Text(greeting.greet())
Enter fullscreen mode Exit fullscreen mode

On iOS, shared Kotlin code can be exposed through a framework or another supported integration mechanism.

A simplified Swift usage example:

let greeting = Greeting()
Text(greeting.greet())
Enter fullscreen mode Exit fullscreen mode

The exact Swift-facing API depends on framework configuration and exported declarations.

Pay attention to:

  • Public API design.
  • Kotlin and Swift type mapping.
  • Nullability.
  • Exception handling.
  • Coroutine and Flow interoperability.
  • Framework size and build integration.
  • Binary compatibility.

Coroutines and Swift concurrency

Shared Kotlin code can expose suspend functions and Flow, but Swift consumption requires an interoperability strategy.

Possible approaches include:

  • Kotlin/Native's supported interop.
  • Swift-facing wrapper APIs.
  • A compatible coroutine/Flow bridging library.
  • SKIE or another compatible integration tool.

Do not assume Kotlin Flow automatically behaves like Swift AsyncSequence without a bridge.

12. Native UI vs Shared UI

Native UI

Android:

@Composable
fun HomeScreen() {
    Text("Welcome Android")
}
Enter fullscreen mode Exit fullscreen mode

iOS:

struct HomeView: View {
    var body: some View {
        Text("Welcome iOS")
    }
}
Enter fullscreen mode Exit fullscreen mode

Both platforms can use the same domain and data logic while maintaining platform-specific UI.

Advantages:

  • Native navigation and interaction patterns.
  • Platform-specific accessibility behavior.
  • Straightforward integration with existing native applications.
  • Freedom to tailor each platform's UX.

Trade-off: UI code and some presentation logic may be duplicated.

Shared UI with Compose Multiplatform

@Composable
fun WelcomeScreen(username: String) {
    Column {
        Text("Welcome, $username")

        Button(onClick = {}) {
            Text("Continue")
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Advantages:

  • Shared UI components.
  • Shared design system.
  • Less duplicated UI implementation.

Trade-offs:

  • Native integrations still need platform work.
  • Platform-specific behavior and accessibility need testing.
  • Shared UI may not be the right choice for every existing product.

Choose based on product requirements, not simply the desire to maximize code sharing.

13. Security in KMP

KMP does not automatically make an application secure. Shared code and platform-specific code both need security reviews.

For authentication, avoid storing sensitive tokens in plain preferences or ordinary database fields without appropriate protection.

A useful architecture is:

Shared authentication repository
              |
       SecureStorage interface
              |
       +------+------+
       |             |
    Android          iOS
    Keystore         Keychain
Enter fullscreen mode Exit fullscreen mode

Common contract:

interface SecureStorage {
    fun saveToken(token: String)
    fun getToken(): String?
    fun clearToken()
}
Enter fullscreen mode Exit fullscreen mode

Each platform provides a secure implementation appropriate to its security model.

Security checklist:

  1. Use Android Keystore-backed protection where appropriate.
  2. Use iOS Keychain for sensitive credentials.
  3. Never hardcode private API secrets in the client.
  4. Never log access tokens or refresh tokens.
  5. Use secure network transport.
  6. Validate authorization on the backend.
  7. Handle refresh-token rotation and invalidation.
  8. Protect sensitive local data.
  9. Review root/jailbreak threat models where relevant.
  10. Keep platform-specific security integrations behind clear interfaces.

14. Testing KMP Applications

Shared tests help verify business logic consistently across targets.

Example validator:

class EmailValidator {
    fun isValid(email: String): Boolean =
        email.contains("@") && email.contains(".")
}
Enter fullscreen mode Exit fullscreen mode

Tests:

class EmailValidatorTest {
    private val validator = EmailValidator()

    @Test
    fun validEmailReturnsTrue() {
        assertTrue(
            validator.isValid("test@example.com")
        )
    }

    @Test
    fun invalidEmailReturnsFalse() {
        assertFalse(
            validator.isValid("invalid-email")
        )
    }
}
Enter fullscreen mode Exit fullscreen mode

This is intentionally a simplified validation example; real email validation should follow the application's requirements.

Testing strategy

Layer Testing approach
Domain Common unit tests
Use cases Unit tests with fakes
Repository Integration tests
Ktor MockEngine tests
Database SQLDelight tests
Android UI Compose UI tests
iOS UI XCTest / SwiftUI tests
Platform integration Android and iOS integration tests

Passing common tests does not guarantee that the iOS application works correctly. Test framework integration, native APIs, database drivers, coroutine bridging, permissions, and real-device behavior too.

15. Performance Considerations

KMP does not automatically make an application faster or slower. Performance depends on implementation and platform integration.

Consider:

  • Database indexes and query efficiency.
  • Pagination and caching.
  • Network timeouts and request duplication.
  • Application startup work.
  • Memory ownership across platform boundaries.
  • Coroutine cancellation and structured concurrency.
  • Framework and dependency size.
  • Release-build benchmarks on actual devices.

Measure before optimizing. Test Android and iOS separately because platform behavior and bottlenecks can differ.

16. Real-World Project: Enterprise Task Management App

Imagine building a task management application for Android and iOS.

Requirements:

  • Login and OTP verification.
  • Role-based access.
  • Task creation and assignment.
  • Task status and priority.
  • Offline task management.
  • Push notifications.
  • Image and document uploads.
  • Real-time updates.
  • Secure token storage.
  • Synchronization across devices.

A possible architecture:

                 ANDROID APP
                Jetpack Compose
                      |
                      |
                   SHARED KMP
                      |
          +-----------+-----------+
          |           |           |
        Domain       Data     Shared state
          |           |
       Use cases   Repository
                      |
                +-----+------+
                |            |
               Ktor      SQLDelight
                |            |
                +-----+------+
                      |
               Platform APIs
                /         \
           Android         iOS
           Keystore       Keychain
           FCM             APNs
           Camera          Camera
           Permissions     Permissions
Enter fullscreen mode Exit fullscreen mode

A feature-oriented structure could be:

shared/
|
+-- core/
|   +-- network/
|   +-- database/
|   +-- security/
|   +-- logging/
|
+-- feature-auth/
|   +-- domain/
|   +-- data/
|
+-- feature-task/
|   +-- domain/
|   +-- data/
|
+-- feature-profile/
|   +-- domain/
|   +-- data/
|
+-- feature-notification/
|
+-- platform/
    +-- android/
    +-- ios/
Enter fullscreen mode Exit fullscreen mode

Start with a single shared module if the project is small. Introduce more Gradle modules when they provide meaningful dependency boundaries, build improvements, or team ownership.

Scenario A: User login

Login screen
    |
Login presentation logic
    |
Login use case
    |
Authentication repository
    |
Ktor API
    |
Backend authentication
    |
Tokens returned
    |
Platform secure storage
Enter fullscreen mode Exit fullscreen mode

Handle input validation, network failures, token expiry, refresh coordination, logout, and credential invalidation.

Scenario B: Offline task creation

  1. Save the task locally.
  2. Display it immediately.
  3. Mark it as pending synchronization.
  4. Detect suitable opportunities to sync.
  5. Upload it to the backend.
  6. Handle server conflicts.
  7. Update the local record.

Scenario C: Push notifications

Android commonly uses Firebase Cloud Messaging. iOS uses APNs, potentially through Firebase Messaging integration.

Share notification models, business rules, and navigation decisions where appropriate. Keep token registration, permission prompts, and platform notification handling in platform-specific code.

Scenario D: Document upload

Share validation rules, upload contracts, repository logic, progress state, and error mapping. Keep file picking and platform-specific file access in native integrations.

Scenario E: Real-time updates

You can share message models, business event processing, and repository logic. However, connection lifecycle, background execution, and platform restrictions must be handled carefully on each platform.

17. Common KMP Mistakes

Mistake Better approach
Trying to share every line of code Share logic that is genuinely common
Assuming KMP requires shared UI Choose native or shared UI deliberately
Putting API calls directly in UI Use use cases and repositories
Using expect/actual for everything Prefer common abstractions where practical
Ignoring iOS integration Test Swift interoperability early
Storing tokens insecurely Use platform-secure storage
Ignoring offline scenarios Design synchronization explicitly
Assuming common tests are sufficient Add platform integration tests
Over-modularizing from day one Extract modules when boundaries justify them
Ignoring lifecycle and background restrictions Integrate with native platform lifecycle rules

18. Kotlin Multiplatform Interview Questions and Answers

Beginner-level questions

1. What is Kotlin Multiplatform?

KMP is a technology that allows Kotlin code to be shared across multiple platforms, including Android and iOS.

2. What is the main purpose of KMP?

To reduce duplicated code by sharing common business logic and other suitable functionality while retaining platform-specific capabilities.

3. What is the difference between KMP and Compose Multiplatform?

KMP enables Kotlin code sharing. Compose Multiplatform enables shared declarative UI on supported platforms.

4. Can we use native UI with KMP?

Yes. Android can use Jetpack Compose and iOS can use SwiftUI while both consume shared Kotlin logic.

5. What is commonMain?

The source set containing shared production Kotlin code.

6. What is androidMain?

The source set for Android-specific implementations.

7. What is iosMain?

The source set used for configured iOS target implementations.

8. What are expect and actual?

expect declares a common API requirement, and actual provides the platform-specific implementation.

9. Can KMP share database logic?

Yes. Libraries such as SQLDelight support multiplatform database access.

10. Can KMP share networking?

Yes. Ktor Client is commonly used to write shared networking code.

Intermediate-level questions

11. What is the difference between KMP and Flutter?

KMP focuses on sharing Kotlin code and can retain native UI. Flutter uses Dart and its own UI framework. KMP can also use Compose Multiplatform for shared UI.

12. How does KMP communicate with iOS?

Kotlin/Native can expose shared Kotlin code through supported framework integration and Objective-C/Swift interoperability.

13. What is Kotlin/Native?

It is the Kotlin compiler technology that compiles Kotlin code to native binaries for supported targets, including Apple platforms.

14. Can we use Kotlin Coroutines in iOS?

Yes. Shared Kotlin code can use coroutines, but Swift consumption of asynchronous APIs needs an appropriate interoperability strategy.

15. What is Koin?

A Kotlin-first dependency injection framework often used to define shared and platform-specific dependencies in KMP projects.

16. What is Ktor?

A Kotlin framework for client and server development. Ktor Client is frequently used for shared HTTP networking.

17. What is SQLDelight?

A library that generates type-safe Kotlin APIs from SQL statements and supports multiplatform database implementations.

18. How do you handle platform-specific APIs?

Use expect/actual, interfaces with platform implementations, or dependency injection.

19. Can Android and iOS use different UI implementations with shared business logic?

Yes. This is a common KMP architecture.

20. What are the benefits of KMP over two independent implementations?

It can reduce duplicated business logic, improve consistency, and simplify maintenance of shared functionality.

Advanced-level questions

21. How do you design Clean Architecture in KMP?

Separate presentation, domain, and data responsibilities. Keep domain logic independent of platform frameworks and inject platform implementations through abstractions.

22. How do you handle secure token storage?

Use a shared secure-storage contract with platform-specific implementations backed by Android Keystore and iOS Keychain.

23. How do you implement offline-first architecture?

Use a local database as a source of truth, record pending operations, synchronize with the backend, and handle conflicts and retries.

24. How do you manage dependency injection across platforms?

Define common dependency modules and supply platform-specific dependencies through platform modules.

25. How do you test shared KMP code?

Use commonTest for common logic and platform-specific tests for native integration.

26. How does iOS consume a Kotlin shared framework?

Shared Kotlin code can be compiled and exposed through an iOS-compatible framework or another supported integration mechanism. Swift consumes the exported API.

27. What is the difference between a shared repository and a platform-specific repository?

A shared repository implements common data access and business rules. A platform-specific implementation is appropriate when data access depends on native APIs or platform-specific behavior.

28. How do you manage exceptions across Kotlin and Swift?

Define clear error contracts, handle exceptions at interop boundaries, and avoid exposing implementation-specific exceptions unnecessarily.

29. How do you manage Flow in iOS?

Use an appropriate Flow-to-Swift integration strategy, such as a compatible bridge or Swift-facing wrapper. Manage collection and cancellation according to the iOS lifecycle.

30. How do you optimize KMP framework size?

Review dependencies, exported APIs, compiler configuration, and unnecessary framework exposure. Measure release binaries.

Senior-level scenario-based questions

31. You have an existing Android application and want to migrate it to KMP. How would you approach it?

I would avoid rewriting the whole application.

  1. Analyze the existing architecture.
  2. Identify reusable business logic.
  3. Extract pure Kotlin domain models and use cases.
  4. Introduce shared repository contracts.
  5. Move suitable networking and data logic into shared code.
  6. Keep platform-specific functionality behind abstractions.
  7. Integrate the shared module with iOS.
  8. Add common and platform-specific tests.
  9. Migrate features incrementally.

The objective is to reduce migration risk while keeping the existing Android application stable.

32. Android works, but iOS crashes when calling a shared Kotlin API. What would you investigate?

I would investigate framework integration, Swift interoperability, nullability mapping, exception propagation, coroutine bridging, native dependencies, platform-specific implementations, and binary compatibility. I would reproduce the problem in an iOS test environment and inspect native logs.

33. Your application has 100 APIs. Should every API implementation move into commonMain?

Not automatically. I would identify which networking contracts, models, authentication rules, and repository behaviors are common. Native SDK integrations and platform-specific capabilities may remain platform-specific.

34. How would you ensure consistent offline behavior on Android and iOS?

Share data models, business rules, repository contracts, synchronization policies, and conflict resolution. Use a local source of truth, idempotent operations, and tests for concurrent updates and network interruption.

35. Your shared module has become too large. What would you do?

Organize code around business features and technical responsibilities. Introduce Gradle modules when they improve dependency boundaries, build performance, or team ownership.

36. Should networking, database, UI, and business logic all be shared?

Not necessarily. Share code according to product requirements. For an existing native application, start with domain and data logic. Evaluate shared UI separately.

37. A refresh token expires while multiple API requests are running. How would you handle it?

Centralize authentication handling in the networking layer. Coordinate refresh so concurrent requests do not independently refresh the token, retry original requests only when safe, handle refresh-token expiry, clear invalid credentials, and return an authentication-required state to the UI.

38. How would you design a KMP library for multiple applications?

Define a stable public API, keep implementation details internal, minimize platform-specific assumptions, document supported targets, provide tests, manage semantic versioning, and verify binary compatibility.

19. Learning Roadmap: Android Developer to KMP Engineer

If you already know Android development, you do not need to start from zero.

Phase Topics Practical exercise
1 KMP fundamentals and source sets Create Android + iOS shared module
2 expect/actual Implement device information
3 Ktor Build a shared REST API client
4 Koin Configure shared dependency injection
5 SQLDelight Build a shared local database
6 Coroutines and Flow Expose shared asynchronous state
7 Clean Architecture Implement shared use cases and repositories
8 Native integration Call shared Kotlin from Swift
9 Security Integrate Keystore and Keychain
10 Testing Add common and platform integration tests
11 Compose Multiplatform Build a shared UI feature
12 Advanced KMP Modularization, CI/CD, and performance

20. Practical Project: Build a KMP Task Management Application

The best way to learn KMP is to build a real application rather than only reading documentation.

Suggested features:

Authentication

  • Login and registration.
  • OTP verification.
  • Access and refresh tokens.
  • Secure token storage.

Task management

  • Create and update tasks.
  • Assign tasks to users.
  • Update task status.
  • Manage task priority.

Offline support

  • SQLDelight.
  • Local caching.
  • Pending synchronization.
  • Retry mechanism.
  • Conflict resolution.

Architecture

  • MVVM.
  • Clean Architecture.
  • Use Cases.
  • Repository Pattern.
  • Koin.
  • Ktor.

Platforms

  • Android: Jetpack Compose.
  • iOS: SwiftUI initially.
  • Optional shared UI: Compose Multiplatform.

Testing

  • Common unit tests.
  • Repository tests.
  • ViewModel tests.
  • Android integration tests.
  • iOS integration tests.

Build one feature end-to-end before adding more features. For example, implement login across shared domain/data code and both native UIs, then add offline task creation.

21. Final Thoughts

Kotlin Multiplatform is valuable because it gives Kotlin developers a way to share business logic across platforms without abandoning native development.

The biggest advantage is not simply writing fewer lines of code. It is creating consistent business behavior across platforms while preserving the capabilities and user experience each platform needs.

For Android developers, a practical learning path is to start by sharing domain logic, networking, repositories, and database operations. Once you understand the architecture and native integration, explore Compose Multiplatform.

Remember: The goal of KMP is not to make Android and iOS identical. The goal is to share what should be shared and preserve what should remain platform-specific.

Related Reading


About the Author

Padmakar Garg is an Android Developer with 8+ years of experience in Kotlin, Java, Jetpack Compose, Kotlin Multiplatform, scalable architecture, mobile security, and high-performance app development.

Top comments (0)