Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Intro to Kotlin/Native and Multi-platform Projects

Intro to Kotlin/Native and Multi-platform Projects

Avatar for Dmitriy Gorbunov

Dmitriy Gorbunov

May 29, 2019
Tweet

More Decks by Dmitriy Gorbunov

Other Decks in Programming

Transcript

  1. Kotlin/Native • Маленький размер рантайма (Hello World ~ 850 KB)

    • Встроенный GC • C Interop • Objective-C and Swift Interop
  2. Kotlin/Native Target Platforms ❏ Windows (x86_64) ❏ Linux (x86_64, arm32,

    MIPS, MIPS little endian) ❏ MacOS (x86_64) ❏ iOS (arm32, arm64, x64) ❏ Android (arm32, arm64) ❏ STM32 ❏ WebAssembly (wasm32)
  3. Kotlin/Native Binaries ➔ Executable file (*.kexe) ➔ Kotlin/Native library (*.klib)

    ➔ Apple framework (Obj-C framework) ➔ Dynamic library (*.so, *.dylib, *.dll) ➔ Static library
  4. Platform-Specific Declarations // Common expect fun platformName(): String // Android

    actual fun platformName(): String { return "Android ${Build.VERSION.RELEASE}" } // iOS actual fun platformName(): String { return UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion }
  5. Platform-Specific Declarations // Common expect fun platformName(): String // Android

    actual fun platformName(): String { return "Android ${Build.VERSION.RELEASE}" } // iOS actual fun platformName(): String { return UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion }
  6. Multiplatform Module Common main expect class Bar fun foo(b: Bar)

    {} Android main actual class Bar {} iOS main actual class Bar {}
  7. Multiplatform Module import platform.UIKit.UIDevice actual fun platformName(): String { return

    UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion }
  8. Shared Code Android View Presenter Repository DTO iOS View Interactor

    Entity API DB SDK KTOR SQLDelight kotlinx serialization ?
  9. Shared Code Android View ViewModel ? Repository DTO iOS View

    Interactor Entity API DB SDK KTOR SQLDelight kotlinx serialization ?
  10. Issues • Multi-threaded coroutines https://github.com/Kotlin/kotlinx.coroutines/issues/462 • UI dispatcher for iOS

    https://github.com/Kotlin/kotlinx.coroutines/issues/470 • Kotlin Generics to Swift Generics https://github.com/JetBrains/kotlin-native/issues/2429 • Kotlinx.serialization https://github.com/Kotlin/kotlinx.serialization/issues/395
  11. Links • Официальный туториал https://kotlinlang.org/docs/tutorials/native/mpp-ios-android.html • Семпл приложения под Android

    и iOS https://github.com/MobileUpLLC/Multiplatform-Sample • KotlinConf App - пример рабочего приложения от Jetbrains https://github.com/JetBrains/kotlinconf-app