Hello, Habr! I am Misha Ignatov, team lead in the Pro company. My team is responsible for client-side mobile apps for Android and iOS. We have been using Kotlin Multiplatform in production since 2019. I'll tell you why we chose this particular technology, how we introduced it, what key stages we went through and what conclusions we made.
Briefly about Kotlin Multiplatform
Kotlin Multiplatform , Kotlin, . 2020 JetBrains Kotlin Multiplatform Mobile () โ SDK, Android iOS. โ -. UI- , .
Kotlin Multiplatform
- . , React Native Flutter , . Kotlin Multiplatform .
, Kotlin, . . Android jar aar-, iOS โ Universal Framework. .
Kotlin Swift
iOS-. โ . , , .
- . 70% , . , , . , , โ Android Kotlin iOS Swift. โ - UX ( : , , , ..).
. , . โ , . , .
1.
โ API-, .
GraphQL. โ multiline . , . , . , - . ยซยป . .
ยซยป . . , ยซยป .
. Android- shared. - object
, . โ iOS-.
package ru.profi.shared.queries.client.city
/**
* [Params.term]
*/
object GeoSelectorWarpQuery : WarpQuery<Params> {
override val hash: String? = "\$GQLID{c9d4adbb7b9ef49fc044064b9a3e662b}"
override val dirtyQuery = listOf("\$term").let { (term) ->
"""
query geoSelector($term: String) {
suggestions: simpleGeoSelector(term: $term, first: 100) {
edges {
node {
name
geoCityId
regionName
hostname
countryId
}
}
}
}
"""
}.trimIndent()
}
Android
override fun getQuery() = GeoSelectorWarpQuery.getQuery()
iOS
import KotlinComponents
struct GraphQLWarpRequests {
static let GeoSelectorWarpQuery = GeoSelectorWarpQuery()
...
}
let model = GraphQLRequestModel(query: GraphQLWarpRequests.GeoSelectorWarpQuery.getQuery(), variables: variables)
. , . iOS 0,8 . ยซยป .
, Kotlin. , pull request backend. , .
Kotlin ultiplatform. .
2. SDK
in-house Clickhouse. backend API . . , , , , .
. network client โ ktor. .
, . SQLDelight โ .
kotlinx.coroutines. kotlinx.serialization.
Android , iOS ยซยป . XCode Firebase Crashlytics . , .
, CrashKiOS Touchlab. CoroutineExceptionHandler, .
, . ยซยป. โ CoroutineScope
.
Kotlin Multiplatform . SDK .
3. - Android
, , . , , .
iOS - . . โ Objective-C . , .
Android - Kotlin. iOS.
Kotlin Multiplatform gradle-.
, , sourceSets .
- commonMain.
, JVM Android,commonMain
. , .
JVM/Android .
org.json kotlinx.serialization JodaTime klock.expect/actual
.
commonMain JVM- , .
, JVMIOException
kotlin.Exception
,ConcurrentHashMap
Stately.
commonMain Android- , .
Android SDKService
,WebSocket
. Kotlin .
SocketService
.
SocketService
interface SocketService { /** * [chatUrl]. [callback] */ fun connect(chatUrl: String, callback: (SocketEvent) -> Unit) /** * . */ fun disconnect() /** * [msg] */ fun send(msg: String) }
API .
iOS runtime- Kotlin, SDK callbackonError
. .
- . .
IceRock.dev . .
Kotlin Multiplatform - . UI UX . , - , .
. Kotlin Multiplatform โ iOS . Android- iOS. , .
. Android- build- . . iOS- , Gradle. .
โ iOS. , , iOS . . Kotlin , .
. , KMM , . Kotlin Multiplatform . . Slack Telegram, Kotlin Multiplatform.
, . , . , . . , .
Now we already have 10 common modules of varying complexity, and we continue to move business logic into common code. I am sure that Kotlin Multiplatform Mobile is ready to conquer the world of mobile application development.