Master Kotlin Multiplatform: Essential Interview Questions for All Levels
Prepare for your next Kotlin Multiplatform interview with these 30 carefully curated questions. Covering basic concepts to advanced scenarios, this guide helps freshers, developers with 1-3 years experience, and seasoned professionals with 3-6+ years master Kotlin Multiplatform development. Each question includes practical examples and code snippets ready for real-world projects.
Basic Kotlin Multiplatform Questions (1-10)
1. What is Kotlin Multiplatform and what are its primary benefits?
Kotlin Multiplatform enables sharing code across multiple platforms like JVM, Native, JavaScript, and more from a single codebase. Key benefits include reduced duplication, consistent business logic across platforms, and faster development cycles using familiar Kotlin syntax.
2. How do you declare the expect/actual mechanism in Kotlin Multiplatform?
The expect/actual pattern declares platform-agnostic APIs in common code and provides platform-specific implementations. This maintains type safety across targets.
// commonMain/kotlin
expect fun getPlatformName(): String
// androidMain/kotlin
actual fun getPlatformName(): String = "Android"
// iosMain/kotlin
actual fun getPlatformName(): String = "iOS"
3. What is the commonMain source set in Kotlin Multiplatform projects?
commonMain contains shared Kotlin code that compiles for all targets. It includes business logic, data models, and platform-agnostic utilities accessible from all platform-specific source sets.
4. How does Kotlin Multiplatform handle platform-specific dependencies?
Platform-specific dependencies are declared in source sets like androidMain, iosMain, or jsMain. Common code uses the expect/actual pattern to access these dependencies through unified APIs.
5. What source sets are automatically created in a new Kotlin Multiplatform project?
A standard KMP project creates commonMain, commonTest, androidMain, androidUnitTest, iosMain, iosTest, and sometimes jsMain source sets depending on the configured targets.
6. Explain the difference between shared module and common code in KMP.
Shared module refers to the entire Kotlin Multiplatform module containing all source sets. Common code specifically means code in commonMain that runs unchanged across all platforms.
7. How do you create a data class in commonMain for multiplatform use?
Data classes in commonMain work across all platforms and provide equals(), hashCode(), toString(), and copy() automatically.
// commonMain/kotlin
data class User(
val id: Long,
val name: String,
val email: String
)
8. What Kotlin standard library functions are guaranteed to work in commonMain?
Core functions like collections (filter, map, fold), strings, null safety operators, and basic math operations are fully supported in commonMain across all targets.
9. How do you handle logging in Kotlin Multiplatform common code?
Use the expect/actual pattern with a common logging interface. Each platform provides its actual implementation (Logcat on Android, NSLog on iOS).
expect fun log(message: String)
10. What is platform.invariant in Kotlin Multiplatform?
platform.invariant provides a platform-specific String instance from a common String. Useful when needing platform-native string representations.
Intermediate Kotlin Multiplatform Questions (11-20)
11. How do you implement coroutines in Kotlin Multiplatform?
Coroutines work in commonMain with kotlinx-coroutines-core. Use suspend functions and common dispatchers like Dispatchers.Default.
// commonMain/kotlin
import kotlinx.coroutines.*
suspend fun fetchData(): String {
delay(1000)
return "Data loaded"
}
12. Explain how to create a multiplatform HTTP client.
Use Ktor’s multiplatform HTTP client in commonMain. It works across JVM, Native, and JavaScript targets seamlessly.
// commonMain/kotlin
import io.ktor.client.*
import io.ktor.client.request.*
val client = HttpClient()
suspend fun getData(): String = client.get("https://api.example.com/data")
13. How do you ensure thread safety in Kotlin Multiplatform shared modules?
Use kotlinx.coroutines Mutex for shared state protection or AtomicReference for simple value updates. Always use suspend functions with proper dispatchers.
import kotlinx.coroutines.sync.Mutex
val mutex = Mutex()
suspend fun updateCounter() = mutex.withLock { counter++ }
14. What are the limitations of JSON serialization in Kotlin Multiplatform?
kotlinx.serialization requires @Serializable annotations and has platform-specific limitations. Use polymorphic serialization carefully across targets.
15. How do you handle platform-specific file I/O in KMP?
Create expect/actual functions for file operations. Common code calls these platform-agnostic APIs while platforms implement native file handling.
expect class FileManager {
suspend fun readFile(path: String): String
suspend fun writeFile(path: String, content: String)
}
16. Explain multiplatform dependency injection patterns.
Use Koin or Kodein with multiplatform modules. Define common modules in commonMain and platform-specific modules in target source sets.
17. How do you implement database access in Kotlin Multiplatform?
Use SQLDelight which generates type-safe Kotlin APIs from SQL. Works across all platforms with a single schema definition.
18. What is the role of Gradle in Kotlin Multiplatform projects?
Gradle manages multiplatform plugins, source sets, targets, and dependencies. The kotlin-multiplatform plugin handles compilation for all targets.
19. How do you test common code in Kotlin Multiplatform?
Write tests in commonTest using kotlinx-coroutines-test. Tests run across all platforms verifying shared logic consistency.
20. Explain binary compatibility in Kotlin Multiplatform Native.
Kotlin/Native uses framework and library modes. Frameworks export APIs for Swift/Objective-C while libraries remain internal to Kotlin.
Advanced Kotlin Multiplatform Questions (21-30)
21. How does Kotlin Multiplatform integrate with Swift on iOS?
Compiled Kotlin/Native produces frameworks consumable by Xcode. Use cinterop for C libraries and @ObjCName annotations for Swift compatibility.
22. Implement a multiplatform caching layer for Atlassian projects.
Create a common cache interface with platform-specific implementations using SharedPreferences (Android) and UserDefaults (iOS).
expect class CacheManager {
suspend fun get(key: String): String?
suspend fun put(key: String, value: String)
}
23. Design a multiplatform navigation system for a Salesforce mobile app.
Use sealed classes in commonMain for navigation events. Platforms implement native navigation (Jetpack Navigation, SwiftUI NavigationStack).
sealed class Screen {
object Home : Screen()
data class Profile(val userId: Long) : Screen()
}
24. How do you handle multiplatform date/time operations?
Use kotlinx-datetime library providing stable APIs across platforms. Avoid java.time which isn’t available on Native/JavaScript.
25. Implement error handling strategy for Paytm‘s shared business logic.
Define sealed Result class in commonMain. Platforms map to native exceptions while maintaining type-safe error handling.
sealed class Result<T> {
data class Success<T>(val data: T) : Result<T>()
data class Error<T>(val exception: Throwable) : Result<T>()
}
26. What are the performance considerations for Kotlin/JS targets?
Optimize bundle size with @JsExport, use sequences for lazy evaluation, and minimize DOM interactions. Consider WebAssembly for compute-heavy tasks.
27. How do you structure large-scale KMP projects for Swiggy?
Use multi-module Gradle structure with feature modules. Shared modules contain domain logic while platform modules handle UI and platform APIs.
28. Implement multiplatform image loading for Zoho apps.
Create expect/actual ImageLoader interface. Android uses Coil, iOS uses native image loading, common code handles caching and transformations.
29. Explain Kotlin Multiplatform Gradle caching strategies.
Enable Gradle build cache, configure incremental compilation, and use composite builds. Platform-specific tasks run in parallel when possible.
30. Design a multiplatform authentication module for Adobe creative tools.
Common module handles JWT parsing, token refresh logic, and secure storage abstraction. Platforms implement biometric auth and keychain integration.
expect class SecureStorage {
suspend fun saveToken(token: String)
suspend fun getToken(): String?
suspend fun clear()
}
Master these Kotlin Multiplatform questions to excel in technical interviews. Practice implementing these patterns in real KMP projects to solidify your understanding across all experience levels.