$30 off During Our Annual Pro Sale. View Details »

Kotlin Multiplatform in Production

Kotlin Multiplatform in Production

Kotlin Multiplatform is steadily making its way into production applications. We (Touchlab) are working with a bunch of orgs to make that happen. This talk kind of wanders through a whole bunch of tangentially related topics. It also has a bunch of links.

Kevin Galligan

October 08, 2020
Tweet

More Decks by Kevin Galligan

Other Decks in Technology

Transcript

  1. Kotlin Multiplatform in Production
    Kevin Galligan

    View Slide

  2. Touchlab

    View Slide

  3. View Slide

  4. Kotlin Multiplatform in Production
    hmm

    View Slide

  5. What are KMP/KMM?

    View Slide

  6. Kotlin Multiplatform (KMP)

    View Slide

  7. Common
    JVM JS Native

    View Slide

  8. It’s the interop
    generally very good

    View Slide

  9. Common
    JVM JS Native

    View Slide

  10. Common
    JVM JS Native
    iOS Mac
    Linux Windows
    Android/NDK Wasm
    Others…
    Java-6 Java-8
    Android
    Browser
    Node
    Typescript(?)

    View Slide

  11. Kotlin Multiplatform Mobile
    (KMM)

    View Slide

  12. KMM
    •is mostly a branding designation (it’s still KMP)
    •has a dedicated website and docs to help get started
    •has an Android Studio plugin built just for mobile (ish)

    View Slide

  13. View Slide

  14. Why KMP/KMM?

    View Slide

  15. kot·lin mul·ti·plat·form
    /ˌkätˈlin məltiˈplatfôrm,ˌkätˈlin məltīˈplatfôrm/
    noun
    noun: kotlin multiplatform
    1.optional, natively-integrated, open-source, code sharing platform, based on the popular,
    modern language kotlin. facilitates non-ui logic availability on many platforms.

    View Slide

  16. kot·lin mul·ti·plat·form
    /ˌkätˈlin məltiˈplatfôrm,ˌkätˈlin məltīˈplatfôrm/
    noun
    noun: kotlin multiplatform
    1.optional, natively-integrated, open-source, code sharing platform, based on the popular,
    modern language kotlin. facilitates non-ui logic availability on many platforms.
    Oh, and JetBrains!

    View Slide

  17. Shared Native Code
    not “cross platform”

    View Slide

  18. Android is Kotlin
    half of it isn’t “cross platform”

    View Slide

  19. Not (necessarily) UI
    Compose and Swift UI compatible!

    View Slide

  20. Low Risk
    bigger orgs worry about such

    View Slide

  21. Production!

    View Slide

  22. Who’s shipping?
    Cash (Square), Plangrid, Careem,
    Quizlet, Down Dog, Target,
    VMWare, Wayfair, Clue, Skip the
    Dishes

    View Slide

  23. mParticle
    shipping a library generator

    View Slide

  24. Covid-related App
    still in “need to know” status

    View Slide

  25. Getting Started

    View Slide

  26. https://kotlinlang.org/lp/mobile/

    View Slide

  27. github.com/touchlab/KaMPKit

    View Slide

  28. Production?
    seems intro to me…

    View Slide

  29. Tooling

    View Slide

  30. Intellij
    the safe choice

    View Slide

  31. Android Studio Plugin!

    View Slide

  32. Xcode Plugin

    View Slide

  33. All use lldb
    deep in the weeds, but…

    View Slide

  34. View Slide

  35. Crash Reporting
    CrashKiOS

    View Slide

  36. View Slide

  37. View Slide

  38. github.com/touchlab/CrashKiOS

    View Slide

  39. Package Managers
    (here be dragons)

    View Slide

  40. JS Stuff
    npm? Typescript?

    View Slide

  41. Libraries

    View Slide

  42. Check out KaMP KIt
    mostly what we’re using in prod

    View Slide

  43. What’s missing?
    bad news section

    View Slide

  44. expect class Date {
    fun toLongMillis(): Long
    }
    expect class DateFormatHelper(format: String) {
    fun toConferenceDate(s: String): Date
    fun toLocalDate(s: String): Date
    fun formatConferenceTZ(d: Date): String
    fun formatLocalTZ(d: Date): String
    }

    View Slide

  45. Great Time To Start!
    still lots of stuff to make

    View Slide

  46. Integrating

    View Slide

  47. “Selling” KMP/KMM
    not everybody loves it

    View Slide

  48. Start with Empathy
    “Javascript can do everything!”

    View Slide

  49. Find Allies
    iOS build config is difficult

    View Slide

  50. Modifying an iOS any prod build is tough
    recruit the experts

    View Slide

  51. kot·lin mul·ti·plat·form
    /ˌkätˈlin məltiˈplatfôrm,ˌkätˈlin məltīˈplatfôrm/
    noun
    noun: kotlin multiplatform
    1.optional, natively-integrated, open-source, code sharing platform, based on the popular,
    modern language kotlin. facilitates non-ui logic availability on many platforms.
    Oh, and JetBrains!
    not “cross platform”

    View Slide

  52. Pick Something Nobody Likes
    few love core data

    View Slide

  53. “Selling” KMP/KMM Links
    • Starter Kit: Kotlin Multiplatform (KMP) for iOS Developers

    https://go.touchlab.co/kmpsell
    • Introduce your team to KMM

    https://kotlinlang.org/docs/mobile/introduce-your-team-to-
    kmm.html

    View Slide

  54. Actually Integrating
    what I thought this talk would be about

    View Slide

  55. Common
    Android iOS
    Framework
    Android
    Stuff
    iOS
    Stuff

    View Slide

  56. Greenfield
    Common
    Android iOS
    Framework
    Android
    Stuff
    iOS
    Stuff

    View Slide

  57. Ship Binary
    Common
    Android iOS
    Framework
    Android
    Stuff
    iOS
    Stuff

    View Slide

  58. Kotlin Xcode Plugin
    intro to Kotlin for iOS devs

    View Slide

  59. Why not both?
    Common
    Android iOS
    Framework
    Android
    Stuff
    iOS
    Stuff

    View Slide

  60. Big Topic
    every team is different

    View Slide

  61. View Slide

  62. Assorted Info and “Bad News”

    View Slide

  63. Concurrency
    it’s different, but changing

    View Slide

  64. Two Rules
    one thread == mutable
    many threads == immutable (frozen)

    View Slide

  65. That is Changing
    realistically 2nd half of next year

    View Slide

  66. Your Code Won’t Change (much)
    unless you do a lot of concurrency management

    View Slide

  67. Concurrency Links
    • KMM Concurrency Overview

    https://kotlinlang.org/docs/mobile/concurrency-overview.html
    • Kotlin/Native Concurrency Handson

    https://play.kotlinlang.org/hands-on/
    Kotlin%20Native%20Concurrency/00_Introduction
    • Thoughts on the changes

    https://medium.com/@kpgalligan/kotlin-native-concurrency-
    changes-bbb1a5147e6
    • More deep dive video

    https://www.youtube.com/watch?v=oxQ6e1VeH4M

    View Slide

  68. You must learn it
    or wait till late 2021

    View Slide

  69. Kotlinx Coroutines
    two libraries

    View Slide

  70. Ktor and iOS
    https://medium.com/@kpgalligan/ktor-and-kotlin-native-fb5c06cb920a

    View Slide

  71. Simple Answer
    Kotlin 1.4.* and MT coroutines

    View Slide

  72. Single Xcode Framework
    this is a big one

    View Slide

  73. DB
    KT
    Framework
    iOS
    Stuff
    Contacts
    Products
    Analytics
    stdlib

    View Slide

  74. DB
    KT Contacts
    iOS
    Stuff
    Contacts
    Products
    Analytics
    stdlib KT Products
    KT Analytics
    KT stdlib

    View Slide

  75. DB
    KT Contacts/
    Products
    iOS
    Stuff
    Contacts
    Products
    Analytics
    stdlib
    KT Analytics

    View Slide

  76. Single Framework Links
    • Multiple Kotlin Frameworks in an Application

    https://touchlab.co/multiple-kotlin-frameworks-in-application/
    • Kotlin team tickets

    https://youtrack.jetbrains.com/issue/KT-42247

    https://youtrack.jetbrains.com/issue/KT-42250

    View Slide

  77. Binary Size
    generally OK, but complicated

    View Slide

  78. Simple Logic
    150k DL/500k DI

    View Slide

  79. KaMP Kit
    ~1m DL/~4m DI

    View Slide

  80. just kotlin vs swift

    View Slide

  81. View Slide

  82. KT SW

    View Slide

  83. KT SW
    KT-objc

    View Slide

  84. KT
    SW
    KT-objc
    KT
    KT-objc
    KT
    KT-objc
    KT
    KT-objc
    KT
    KT-objc
    KT
    KT-objc
    KT
    KT-objc
    KT
    KT-objc
    KT
    KT-objc
    KT
    KT-objc
    KT
    KT-objc
    KT
    KT-objc
    SW
    SW
    SW
    SW
    SW
    SW
    SW
    SW
    SW
    SW
    SW
    SW
    SW

    View Slide

  85. View Slide

  86. What to do?
    mark them internal

    View Slide

  87. KT
    SW
    KT
    KT
    KT
    KT
    KT
    KT
    KT
    KT
    KT
    KT-objc
    KT
    KT-objc
    KT
    KT-objc
    SW
    SW
    SW
    SW
    SW
    SW
    SW
    SW
    SW
    SW
    SW
    SW
    SW

    View Slide

  88. DB
    KT
    Framework
    iOS
    Stuff
    Contacts
    Products
    Analytics
    stdlib

    View Slide

  89. DB
    KT
    Framework
    iOS
    Stuff
    Contacts
    Products
    Analytics
    stdlib
    iOS
    Adapter

    View Slide

  90. Size Best Practice
    a work in progress

    View Slide

  91. TL;DR
    ~1m DL/~4m DI

    View Slide

  92. Direct Swift Interop
    maybe 2021

    View Slide

  93. Still Early Apopter-ish
    alpha in 1.4

    View Slide

  94. What’s coming?
    2021

    View Slide

  95. • Compiler Plugins
    • Super-solid IDE and tooling support
    • Post-alpha (GA maybe?)
    • Proper WASM :)
    • New memory model
    • Way more library support (date format, file, mock, etc)
    • Compose for iOS? (probably not, but at some point)

    View Slide

  96. Join the Kotlin Slack
    kotlinlang.org/community/

    View Slide

  97. Thanks!
    @kpgalligan
    touchlab.co

    View Slide

  98. Thanks!
    @kpgalligan
    touchlab.co
    Join the team
    !

    View Slide