Prepare for your next Kotlin Multiplatform interview with these 30 carefully curated questions covering basic, intermediate, and advanced concepts. Whether you’re a fresher, have 1-3 years of experience, or are a seasoned developer with 3-6 years, this guide provides clear explanations and practical examples focused exclusively on Kotlin Multiplatform development.
Basic Kotlin Multiplatform Questions
1. What is Kotlin Multiplatform and what are its main benefits?
Kotlin Multiplatform allows developers to share code across multiple platforms like Android, iOS, web, and desktop using Kotlin. Main benefits include code reuse, single codebase maintenance, and consistent business logic across platforms.[1][2]
2. How do you declare a multiplatform project structure?
Create a shared module with commonMain, androidMain, and iosMain source sets. The commonMain contains shared code accessible by all platforms.[1]
kotlin {
sourceSets {
val commonMain by getting { ... }
val androidMain by getting { ... }
val iosMain by getting { ... }
}
}
3. What is the expect and actual mechanism in Kotlin Multiplatform?
expect declarations in commonMain define platform-agnostic APIs. actual implementations in platform-specific source sets provide the concrete implementations.[1]
// commonMain
expect fun getPlatformName(): String
// androidMain
actual fun getPlatformName(): String = "Android"
4. How do you create a simple data class in the shared module?
Data classes work seamlessly in common code and automatically provide equals(), hashCode(), toString(), and copy() methods.
data class User(
val id: Long,
val name: String,
val email: String
)
5. What are source sets in Kotlin Multiplatform?
Source sets organize code by platform and configuration. commonMain for shared code, androidMain for Android-specific, iosMain for iOS-specific, and hierarchical sets like androidAndroidTest for platform-specific tests.[1]
6. How do you handle platform-specific dependencies?
Declare dependencies in platform-specific source sets. Common dependencies go in commonMain, Android dependencies in androidMain, and iOS dependencies in iosMain.
kotlin {
sourceSets {
commonMain {
dependencies { implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3") }
}
androidMain { ... }
}
}
Intermediate Kotlin Multiplatform Questions
7. How do you implement coroutines in a Kotlin Multiplatform shared module?
Add kotlinx-coroutines-core to commonMain. Use suspend functions and coroutine builders like launch and async that work across all platforms.[3]
suspend fun fetchUserData(): User {
delay(1000)
return User(1, "John", "john@example.com")
}
8. How do you ensure thread safety in shared multiplatform code?
Use Mutex from kotlinx.coroutines or AtomicReference. For immutable data, use freeze() to prevent unintended mutations across platforms.[1]
val mutex = Mutex()
suspend fun updateSharedState() = mutex.withLock {
sharedCounter++
}
9. How do you create a multiplatform HTTP client?
Use Ktor client with multiplatform support. Add io.ktor:ktor-client-core to commonMain and platform-specific engines like ktor-client-okhttp for Android and ktor-client-darwin for iOS.[1]
10. Explain sealed classes in Kotlin Multiplatform context.
Sealed classes restrict inheritance to the same package and work perfectly in common code for modeling restricted class hierarchies like API responses or states.[2]
sealed class ApiResult {
data class Success(val data: User) : ApiResult()
data class Error(val message: String) : ApiResult()
}
11. How do you handle platform-specific logging in shared code?
Create an expect function for logging in commonMain with actual implementations using Android’s Log in androidMain and OSLog in iosMain.
expect fun log(message: String)
12. What are Gradle version catalogs and their use in multiplatform projects?
Version catalogs centralize dependency versions in libs.versions.toml. They simplify multiplatform dependency management across modules and platforms.
Advanced Kotlin Multiplatform Questions
13. How do you implement dependency injection in Kotlin Multiplatform?
Use Koin or Kodein with multiplatform support. Define modules in commonMain and platform-specific modules where needed. This ensures consistent DI across all targets.[4]
14. Explain how to structure a large-scale Kotlin Multiplatform project at Atlassian.
Use feature modules in shared code, separate business logic from data layers, apply clean architecture principles, and maintain strict separation between common and platform-specific concerns.[1]
15. How do you optimize binary size in Kotlin Multiplatform iOS targets?
Enable Kotlin/Native optimizations, use stripDebugSymbols, minimize shared framework dependencies, and use KotlincOpt flags for release builds.
16. Implement a multiplatform SQLite database access layer.
Use SQLDelight which generates type-safe Kotlin APIs from SQL. It supports commonMain queries with platform-specific drivers for Android and iOS.[1]
// commonMain
@Query("SELECT * FROM users")
fun getAllUsers(): List
17. How do you handle JSON serialization in Kotlin Multiplatform?
Use kotlinx.serialization with multiplatform support. Define data classes with @Serializable and use Json for encoding/decoding that works across all platforms.
@Serializable
data class User(val name: String, val age: Int)
18. What are the limitations of Kotlin Multiplatform and workarounds?
Limitations include UI layer sharing and some library incompatibilities. Workarounds: separate UI layers, create expect/actual wrappers for missing APIs, and contribute to multiplatform libraries.[1]
19. How do you test shared business logic in Kotlin Multiplatform?
Use Kotest or Kotlin test framework in commonTest. Write pure Kotlin tests that run on all platforms using coroutines test utilities and mocking libraries.[1]
20. Explain multiplatform caching strategies for Salesforce applications.
Implement in-memory cache with LRUCache in common code, disk cache using platform-specific storage (Room/SQLDelight), and network cache with Ktor interceptors.
21. How do you implement multiplatform navigation state management?
Create sealed class hierarchies for routes in commonMain. Use platform-specific navigation (Jetpack Compose Navigation, SwiftUI Navigation) driven by shared state.
22. What is hierarchical source sets and when to use them?
Hierarchical source sets inherit from parent sets. Use commonTest (inherits commonMain), androidUnitTest (inherits commonTest + androidMain) for targeted testing configurations.[1]
23. How do you handle platform-specific resources in shared code?
Use resource management libraries like moko-resources or expect/actual resource accessors. Store strings/images in platform-specific folders accessed through common APIs.
24. Implement error handling strategy for multiplatform networking at Paytm.
Create sealed class hierarchies for network errors in commonMain. Map platform-specific exceptions to common error types in actual implementations.[1]
sealed class NetworkError : Exception() {
object Network : NetworkError()
object Timeout : NetworkError()
data class Server(val code: Int, val message: String) : NetworkError()
}
25. How do you profile performance across platforms in Kotlin Multiplatform?
Use common coroutine debugging tools, platform-specific profilers (Android Studio Profiler, Xcode Instruments), and shared metrics collection for cross-platform comparison.
26. Explain Kotlin/Native memory model and GC-free execution.
Kotlin/Native uses reference counting with cycle collector instead of GC. Use freeze() for immutable data sharing and avoid retain cycles in object graphs.[1]
27. How do you implement multiplatform analytics at Swiggy?
Create analytics event domain models in commonMain. Use expect/actual analytics trackers that forward events to platform-specific SDKs (Firebase Analytics, iOS analytics).
28. What are cinterops and when are they needed in multiplatform?
Cinterops allow calling C libraries from Kotlin/Native. Needed for iOS frameworks without Swift/Kotlin wrappers or when performance-critical native code is required.
29. How do you migrate existing Android code to Kotlin Multiplatform?
Gradually extract business logic to shared module, replace platform-specific APIs with expect/actual, maintain backward compatibility during transition phases.[2]
30. Design a multiplatform architecture for a Zoho-like productivity app.
Layered architecture: Domain (common pure logic), Data (repositories with platform data sources), Presentation (platform-specific UI driven by shared ViewModels/State), Shared utilities/testing infrastructure.[1]