Slide 1

Slide 1 text

Kotlin Multiplatform in Production Kevin Galligan

Slide 2

Slide 2 text

Touchlab

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Kotlin Multiplatform in Production hmm

Slide 5

Slide 5 text

What are KMP/KMM?

Slide 6

Slide 6 text

Kotlin Multiplatform (KMP)

Slide 7

Slide 7 text

Common JVM JS Native

Slide 8

Slide 8 text

It’s the interop generally very good

Slide 9

Slide 9 text

Common JVM JS Native

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

Kotlin Multiplatform Mobile (KMM)

Slide 12

Slide 12 text

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)

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

Why KMP/KMM?

Slide 15

Slide 15 text

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.

Slide 16

Slide 16 text

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!

Slide 17

Slide 17 text

Shared Native Code not “cross platform”

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

Not (necessarily) UI Compose and Swift UI compatible!

Slide 20

Slide 20 text

Low Risk bigger orgs worry about such

Slide 21

Slide 21 text

Production!

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

mParticle shipping a library generator

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

Getting Started

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

github.com/touchlab/KaMPKit

Slide 28

Slide 28 text

Production? seems intro to me…

Slide 29

Slide 29 text

Tooling

Slide 30

Slide 30 text

Intellij the safe choice

Slide 31

Slide 31 text

Android Studio Plugin!

Slide 32

Slide 32 text

Xcode Plugin

Slide 33

Slide 33 text

All use lldb deep in the weeds, but…

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

Crash Reporting CrashKiOS

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

github.com/touchlab/CrashKiOS

Slide 39

Slide 39 text

Package Managers (here be dragons)

Slide 40

Slide 40 text

JS Stuff npm? Typescript?

Slide 41

Slide 41 text

Libraries

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

What’s missing? bad news section

Slide 44

Slide 44 text

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 }

Slide 45

Slide 45 text

Great Time To Start! still lots of stuff to make

Slide 46

Slide 46 text

Integrating

Slide 47

Slide 47 text

“Selling” KMP/KMM not everybody loves it

Slide 48

Slide 48 text

Start with Empathy “Javascript can do everything!”

Slide 49

Slide 49 text

Find Allies iOS build config is difficult

Slide 50

Slide 50 text

Modifying an iOS any prod build is tough recruit the experts

Slide 51

Slide 51 text

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”

Slide 52

Slide 52 text

Pick Something Nobody Likes few love core data

Slide 53

Slide 53 text

“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

Slide 54

Slide 54 text

Actually Integrating what I thought this talk would be about

Slide 55

Slide 55 text

Common Android iOS Framework Android Stuff iOS Stuff

Slide 56

Slide 56 text

Greenfield Common Android iOS Framework Android Stuff iOS Stuff

Slide 57

Slide 57 text

Ship Binary Common Android iOS Framework Android Stuff iOS Stuff

Slide 58

Slide 58 text

Kotlin Xcode Plugin intro to Kotlin for iOS devs

Slide 59

Slide 59 text

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

Slide 60

Slide 60 text

Big Topic every team is different

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

Assorted Info and “Bad News”

Slide 63

Slide 63 text

Concurrency it’s different, but changing

Slide 64

Slide 64 text

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

Slide 65

Slide 65 text

That is Changing realistically 2nd half of next year

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

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

Slide 68

Slide 68 text

You must learn it or wait till late 2021

Slide 69

Slide 69 text

Kotlinx Coroutines two libraries

Slide 70

Slide 70 text

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

Slide 71

Slide 71 text

Simple Answer Kotlin 1.4.* and MT coroutines

Slide 72

Slide 72 text

Single Xcode Framework this is a big one

Slide 73

Slide 73 text

DB KT Framework iOS Stuff Contacts Products Analytics stdlib

Slide 74

Slide 74 text

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

Slide 75

Slide 75 text

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

Slide 76

Slide 76 text

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

Slide 77

Slide 77 text

Binary Size generally OK, but complicated

Slide 78

Slide 78 text

Simple Logic 150k DL/500k DI

Slide 79

Slide 79 text

KaMP Kit ~1m DL/~4m DI

Slide 80

Slide 80 text

just kotlin vs swift

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

KT SW

Slide 83

Slide 83 text

KT SW KT-objc

Slide 84

Slide 84 text

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

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

What to do? mark them internal

Slide 87

Slide 87 text

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

Slide 88

Slide 88 text

DB KT Framework iOS Stuff Contacts Products Analytics stdlib

Slide 89

Slide 89 text

DB KT Framework iOS Stuff Contacts Products Analytics stdlib iOS Adapter

Slide 90

Slide 90 text

Size Best Practice a work in progress

Slide 91

Slide 91 text

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

Slide 92

Slide 92 text

Direct Swift Interop maybe 2021

Slide 93

Slide 93 text

Still Early Apopter-ish alpha in 1.4

Slide 94

Slide 94 text

What’s coming? 2021

Slide 95

Slide 95 text

• 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)

Slide 96

Slide 96 text

Join the Kotlin Slack kotlinlang.org/community/

Slide 97

Slide 97 text

Thanks! @kpgalligan touchlab.co

Slide 98

Slide 98 text

Thanks! @kpgalligan touchlab.co Join the team !