Have you worked with Kotlin Multiplatform?
sobes.tech AI
Answer from AI
Yes, I have worked with it. I created shared logic for iOS and Android using Kotlin Multiplatform Mobile (now part of Kotlin Multiplatform).
I used Ktor for network requests, SQLDelight for database operations, and Koin for dependency injection.
I developed the following layers:
- Data Layer: Handling local data and network.
- Domain Layer: Business logic.
The UI layer remained platform-dependent.
The main advantages I highlighted were:
- Code reuse: Significant reduction in duplicated logic.
- Unified language: Kotlin for both platforms.
- Interoperability: Native interaction with platform-specific code (Swift/Objective-C and Java/Kotlin).
I also noted some challenges:
- Ecosystem maturity: Some libraries may be less mature than platform-specific stacks.
- Debugging: Debugging cross-platform code can be less straightforward.
- CI/CD: Setting up CI/CD pipelines requires attention to KMP specifics.
Here's an example of a simple class from the shared module:
// commonMain
expect class Platform() {
val name: String
}
// androidMain
actual class Platform actual constructor() {
actual val name: String = "Android ${android.os.Build.VERSION.SDK_INT}"
}
// iosMain
actual class Platform actual constructor() {
actual val name: String =
UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion
}
// commonMain
class Greeting {
private val platform: Platform = Platform()
fun greet(): String {
return "Hello, ${platform.name}!"
}
}
In this example, Platform is an expected class, with platform-specific implementations provided via actual. Greeting uses this class to generate a greeting.
My experience with KMP, although not the main focus, showed potential for speeding up development and unifying logic in cross-platform projects.