Hallo Habr! Ich bin Misha Ignatov, Teamleiterin in der Pro-Firma. Mein Team ist verantwortlich für clientseitige mobile Apps für Android und iOS. Wir verwenden Kotlin Multiplatform seit 2019 in der Produktion. Ich werde Ihnen sagen, warum wir diese spezielle Technologie ausgewählt haben, wie wir sie eingeführt haben, welche Schlüsselphasen wir durchlaufen haben und welche Schlussfolgerungen wir gezogen haben.
Kurz über 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.
, . , . , . . , .
Jetzt haben wir bereits 10 gemeinsame Module unterschiedlicher Komplexität und verschieben die Geschäftslogik weiterhin in gemeinsamen Code. Ich bin sicher, dass Kotlin Multiplatform Mobile bereit ist, die Welt der Entwicklung mobiler Anwendungen zu erobern.