Comment Kotlin Multiplatform a été implémenté dans Profi

Bonjour, Habr! Je suis Misha Ignatov, chef d'équipe dans la société Pro. Mon équipe est responsable des applications mobiles côté client pour Android et iOS. Nous utilisons Kotlin Multiplatform en production depuis 2019. Je vais vous dire pourquoi nous avons choisi cette technologie particulière, comment nous l'avons introduite, quelles étapes clés nous avons traversées et quelles conclusions nous avons tirées.





En bref sur Kotlin Multiplatform

Kotlin Multiplatform , Kotlin, . 2020 JetBrains Kotlin Multiplatform Mobile () — SDK, Android iOS. —  -. UI- , .





Kotlin Multiplatform

- . , React Native Flutter , . Kotlin Multiplatform . 









  1. , Kotlin, . . Android jar aar-, iOS — Universal Framework. .





  2. Kotlin Swift





    iOS-. — . , , .









  3. - . 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.





, unit-. , .





Android , iOS «» . XCode Firebase Crashlytics . , .





, CrashKiOS Touchlab. CoroutineExceptionHandler, . 





, . «». — CoroutineScope



.





Kotlin Multiplatform . SDK .





3. - Android

, , . , , .





iOS - . . — Objective-C . , .





Android - Kotlin. iOS.





IceRock.dev. , KMM . .





  1. Kotlin Multiplatform gradle-.

    , , sourceSets .





  2. - commonMain.

    , JVM Android, commonMain



    . , .





  3. JVM/Android .

    org.json kotlinx.serialization JodaTime klock. expect/actual



    .





  4. commonMain JVM- , .

    , JVM IOException



    kotlin.Exception



    , ConcurrentHashMap



    Stately.





  5. commonMain Android- , .

    Android SDK Service



    , WebSocket



    . Kotlin . 





    SocketService



    .





    SocketService
    interface SocketService {
    
        /**
         *     [chatUrl].        [callback]
         */
        fun connect(chatUrl: String, callback: (SocketEvent) -> Unit)
    
        /**
         *      .
         */
        fun disconnect()
    
        /**
         *   [msg]     
         */
        fun send(msg: String)
    }
    
          
          



  6. API .

    iOS runtime- Kotlin, SDK callback onError



    . .





- . .





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.





, . , . , . . , . 





Maintenant, nous avons déjà 10 modules communs de complexité variable, et nous continuons à déplacer la logique métier vers un code commun. Je suis sûr que Kotlin Multiplatform Mobile est prêt à conquérir le monde du développement d'applications mobiles.








All Articles