Halo, Habr! Saya Misha Ignatov, pemimpin tim di perusahaan Pro. Tim saya bertanggung jawab atas aplikasi seluler sisi klien untuk Android dan iOS. Kami telah menggunakan Kotlin Multiplatform dalam produksi sejak 2019. Saya akan memberi tahu Anda mengapa kami memilih teknologi khusus ini, bagaimana kami memperkenalkannya, tahapan utama apa yang kami lalui dan kesimpulan apa yang kami buat.
Secara singkat tentang 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.
, . , . , . . , .
Sekarang kami sudah memiliki 10 modul umum dengan kompleksitas yang berbeda-beda, dan kami terus memindahkan logika bisnis ke dalam kode umum. Saya yakin Kotlin Multiplatform Mobile siap menaklukkan dunia pengembangan aplikasi seluler.