Kotlin Multiplatform(KMP) Interview Questions and Answers
Kotlin Multiplatform (KMP) is getting a lot of attention these days because it allows you to write code once and share it across multiple platforms like Android, iOS, Web, Desktop, and even backend servers.
If you are preparing for interviews related to KMP, this blog will help you with important questions and deep explanations.
1. What is Kotlin Multiplatform?
Kotlin Multiplatform is a technology that lets you share the common code (like business logic, networking, database handling) between different platforms like Android, iOS, web, etc. You only write platform-specific code (like UI, Bluetooth, GPS) where necessary.
Example:
2. Why do we use Kotlin Multiplatform?
We use Kotlin Multiplatform to:
3. What parts of an app can be shared using Kotlin Multiplatform? You can share:
You cannot share:
4. How does Kotlin Multiplatform actually work under the hood?
5. What are the main modules or projects you find in a KMP setup?
6. What are expect/actual keywords in Kotlin Multiplatform?
Example: In shared code:
expect fun getPlatformName(): String
In Android:
actual fun getPlatformName(): String = "Android"
In iOS:
actual fun getPlatformName(): String = "iOS"
7. What is Kotlin/Native?
Kotlin/Native is a part of KMP that compiles Kotlin code to native machine code (like for iOS, macOS, Linux).
8. What is Kotlin Multiplatform Mobile (KMM)?
KMM is a special set of tools and libraries inside KMP focused only on sharing code between Android and iOS.
9. How do you handle Database in Kotlin Multiplatform?
You can use libraries like:
These libraries allow you to write database code once and use it everywhere.
10. How do you handle Networking (API calls) in Kotlin Multiplatform?
You can use libraries like:
You can create APIs once using Ktor and call them from Android and iOS both.
11. How do you share code between Android and iOS?
You create a shared module that contains common logic, and then:
12. Can you use Jetpack Compose in Kotlin Multiplatform?
Answer: Yes! With Compose Multiplatform you can build UI using Compose for:
But for iOS, Compose UI is still under development.
13. What is the difference between Kotlin Multiplatform and Flutter/React Native?
14. What are the challenges of using Kotlin Multiplatform?
15. Future of Kotlin Multiplatform?
16. What is Multiplatform Project Structure in Kotlin?
A typical KMP project has 3 parts:
There are also test folders:
17. How does Dependency Injection work in Kotlin Multiplatform?
You can use:
18. What are the Gradle Plugins used in Kotlin Multiplatform?
Important plugins:
19. What is CocoaPods and why is it needed in KMP?
20. What are some popular libraries compatible with Kotlin Multiplatform?
21. How does Kotlin Serialization work in Multiplatform Projects?
Example:
@Serializable
data class User(val name: String, val age: Int)
22. Can we call Swift/Objective-C code from Kotlin Multiplatform?
Yes! , You can call platform-specific Swift/Obj-C code using expect/actual mechanism or native interop.
23. Can we use Coroutines in Kotlin Multiplatform?
Yes!
24. How do you share Resource files (like images, strings) in Kotlin Multiplatform?
25. How do you perform Testing in Kotlin Multiplatform Projects?
26. When should you NOT use Kotlin Multiplatform?
27. How do you handle platform-specific threading and concurrency in Kotlin Multiplatform?
Example:
fun fetchData() {
GlobalScope.launch(Dispatchers.Main) {
val data = withContext(Dispatchers.IO) { fetchFromNetwork() }
updateUI(data)
}
}
28. What are the challenges of using Kotlin Multiplatform for iOS?
29. How do you integrate third-party libraries in Kotlin Multiplatform?
30. How do you handle debugging Kotlin Multiplatform code across different platforms?
31. What are the differences between suspend and expect functions in Kotlin Multiplatform?
32. How do you manage versioning of Kotlin Multiplatform dependencies?
33. How do you handle platform-specific resources (like images or strings) in Kotlin Multiplatform?
34. Explain the role of kotlinx.serialization in Kotlin Multiplatform and how it works across platforms.
35. How do you handle testing for Kotlin Multiplatform projects?
36. What is the role of Kotlin/Native in Kotlin Multiplatform and how does it work?
37. How do you handle dependencies between shared code and platform-specific code in Kotlin Multiplatform?
38. You’re working on a mobile app that needs to fetch user data and display it in the app. You have to support both Android and iOS platforms. The user data is fetched from a backend API. How would you implement this in Kotlin Multiplatform?
Approach:
Example Code:
// Common code (shared module)
expect fun fetchUserData(): String
// Actual implementation for Android
actual fun fetchUserData(): String {
// Using Retrofit or any other Android networking library
return "User data from Android"
}
// Actual implementation for iOS
actual fun fetchUserData(): String {
// Using Ktor or another iOS networking library
return "User data from iOS"
}
39. You’re developing a mobile app that needs to send push notifications to both Android and iOS. How would you implement this in Kotlin Multiplatform?
Approach:
Example Code:
// Common code (shared module)
expect fun subscribeToPushNotifications()
// Actual implementation for Android
actual fun subscribeToPushNotifications() {
// Use Firebase Cloud Messaging to subscribe to push notifications on Android
FirebaseMessaging.getInstance().subscribeToTopic("user_topic")
}
// Actual implementation for iOS
actual fun subscribeToPushNotifications() {
// Use APNs to subscribe to push notifications on iOS
// Note: iOS code for subscribing to APNs
}
40. You need to implement a feature in your Kotlin Multiplatform app where you fetch data from a backend API. The API response includes a list of items, but the format of the response differs between Android and iOS (different field names). How would you handle this?
Approach:
Example Code:
// Common code (shared module)
@Serializable
expect data class ApiResponse(val id: String, val name: String)
// Actual implementation for Android
actual data class ApiResponse(val id: String, val name: String) {
// Android-specific response mapping
constructor(json: JsonObject) : this(
json.get("userId").jsonPrimitive.content, // Mapping Android-specific field
json.get("userName").jsonPrimitive.content
)
}
// Actual implementation for iOS
actual data class ApiResponse(val id: String, val name: String) {
// iOS-specific response mapping
constructor(json: JsonObject) : this(
json.get("uid").jsonPrimitive.content, // Mapping iOS-specific field
json.get("fullName").jsonPrimitive.content
)
}
41. Your Kotlin Multiplatform app has a feature where the data needs to be saved in local storage. On Android, you’re using Room, but on iOS, you’re using SQLite. How would you handle this in Kotlin Multiplatform?
Approach:
Example Code:
// Common code (shared module)
expect class LocalDatabase {
fun saveData(data: String)
fun getData(): String
}
// Actual implementation for Android (Room)
actual class LocalDatabase actual constructor() {
private val database: AppDatabase = Room.databaseBuilder(
context,
AppDatabase::class.java, "app-database"
).build()
actual fun saveData(data: String) {
// Room-specific code to save data
}
actual fun getData(): String {
// Room-specific code to retrieve data
return "Data from Android"
}
}
// Actual implementation for iOS (SQLite or GRDB)
actual class LocalDatabase actual constructor() {
private val database: SQLiteDatabase = SQLiteDatabase.openOrCreateDatabase("db", null)
actual fun saveData(data: String) {
// iOS-specific code to save data using SQLite
}
actual fun getData(): String {
// iOS-specific code to retrieve data
return "Data from iOS"
}
}
42. You’re developing a Kotlin Multiplatform app, and you need to implement a feature that requires access to platform-specific hardware features (e.g., camera on Android, and photo library on iOS). How would you implement this feature?
Approach:
Example Code:
// Common code (shared module)
expect fun capturePhoto(): String
// Actual implementation for Android
actual fun capturePhoto(): String {
// Android-specific camera logic using CameraX or Camera2 API
return "Photo captured on Android"
}
// Actual implementation for iOS
actual fun capturePhoto(): String {
// iOS-specific camera logic using UIImagePickerController
return "Photo captured on iOS"
}
Summary:
Kotlin Multiplatform is NOT about “write once and forget” — it’s about “write core logic once, build great native apps”. If you love Kotlin and want to work across Android, iOS, and other platforms without learning 5 different languages, then KMP is made for you!
Thank you for reading. 🙌🙏✌.
Found this helpful? Don’t forgot to clap 👏 and follow me for more such useful articles about Android development and Kotlin or buy us a coffee here ☕
If you need any help related to Android, Kotlin. I’m always happy to help you.
Follow me on: