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.

58d1281770fe55a05a96600244ec8341?s=128

Kevin Galligan

October 08, 2020
Tweet

Transcript

  1. Kotlin Multiplatform in Production Kevin Galligan

  2. Touchlab

  3. None
  4. Kotlin Multiplatform in Production hmm

  5. What are KMP/KMM?

  6. Kotlin Multiplatform (KMP)

  7. Common JVM JS Native

  8. It’s the interop generally very good

  9. Common JVM JS Native

  10. Common JVM JS Native iOS Mac Linux Windows Android/NDK Wasm

    Others… Java-6 Java-8 Android Browser Node Typescript(?)
  11. Kotlin Multiplatform Mobile (KMM)

  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)
  13. None
  14. Why KMP/KMM?

  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.
  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!
  17. Shared Native Code not “cross platform”

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

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

  20. Low Risk bigger orgs worry about such

  21. Production!

  22. Who’s shipping? Cash (Square), Plangrid, Careem, Quizlet, Down Dog, Target,

    VMWare, Wayfair, Clue, Skip the Dishes
  23. mParticle shipping a library generator

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

  25. Getting Started

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

  27. github.com/touchlab/KaMPKit

  28. Production? seems intro to me…

  29. Tooling

  30. Intellij the safe choice

  31. Android Studio Plugin!

  32. Xcode Plugin

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

  34. None
  35. Crash Reporting CrashKiOS

  36. None
  37. None
  38. github.com/touchlab/CrashKiOS

  39. Package Managers (here be dragons)

  40. JS Stuff npm? Typescript?

  41. Libraries

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

  43. What’s missing? bad news section

  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 }
  45. Great Time To Start! still lots of stuff to make

  46. Integrating

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

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

  49. Find Allies iOS build config is difficult

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

    experts
  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”
  52. Pick Something Nobody Likes few love core data

  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
  54. Actually Integrating what I thought this talk would be about

  55. Common Android iOS Framework Android Stuff iOS Stuff

  56. Greenfield Common Android iOS Framework Android Stuff iOS Stuff

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

  58. Kotlin Xcode Plugin intro to Kotlin for iOS devs

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

    Stuff
  60. Big Topic every team is different

  61. None
  62. Assorted Info and “Bad News”

  63. Concurrency it’s different, but changing

  64. Two Rules one thread == mutable many threads == immutable

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

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

    of concurrency management
  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
  68. You must learn it or wait till late 2021

  69. Kotlinx Coroutines two libraries

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

  71. Simple Answer Kotlin 1.4.* and MT coroutines

  72. Single Xcode Framework this is a big one

  73. DB KT Framework iOS Stuff Contacts Products Analytics stdlib

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

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

    KT Analytics
  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
  77. Binary Size generally OK, but complicated

  78. Simple Logic 150k DL/500k DI

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

  80. just kotlin vs swift

  81. None
  82. KT SW

  83. KT SW KT-objc

  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
  85. None
  86. What to do? mark them internal

  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
  88. DB KT Framework iOS Stuff Contacts Products Analytics stdlib

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

    Adapter
  90. Size Best Practice a work in progress

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

  92. Direct Swift Interop maybe 2021

  93. Still Early Apopter-ish alpha in 1.4

  94. What’s coming? 2021

  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)
  96. Join the Kotlin Slack kotlinlang.org/community/

  97. Thanks! @kpgalligan touchlab.co

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