Slide 1

Slide 1 text

Adit Lal | 2024 Journey of ups/downs for the real-world KMP apps KMP in Practice: Real world case studies

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Coroutines Null-Safety Extension-Functions Smart-Casts Delegated-Properties Versatility on the Server Side streamlined approach Open Source Modern Language Features Uni fi ed Codebase

Slide 4

Slide 4 text

Kotlin multipla tf Source - https://shorturl.at/xyAPX

Slide 5

Slide 5 text

Kotlin multipla tf orm

Slide 6

Slide 6 text

Kotlin multipla tf orm

Slide 7

Slide 7 text

Kotlin multipla tf orm

Slide 8

Slide 8 text

Kotlin multipla tf orm

Slide 9

Slide 9 text

Kotlin multipla tf orm

Slide 10

Slide 10 text

Kotlin multipla tf orm

Slide 11

Slide 11 text

Multiplatform libraries

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Compose Multiplatform

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Fleet

Slide 16

Slide 16 text

• Flexibility to choose what is shared and what not • Shared code lowers the effort, cost per feature • Shared code ensures consistency amongst platforms KMP - Buy in

Slide 17

Slide 17 text

UseCases - Greenfield #1 a ndroidApp (module) iosApp (module) sh a red (KMP module) a ndroidM a in(source) commonM a in(source) iOSM a in(source) …(source)

Slide 18

Slide 18 text

UseCases - Greenfield #2 a ndroidApp (module) iosApp (module) a n a lytics (sh a red) Network (sh a red)

Slide 19

Slide 19 text

UseCases - Brownfield #1 Android Project Regul a r Android code sh a red (KMP module) a ndroidM a in(source) commonM a in(source) iOSM a in(source) iOS Project Regul a r iOS code Dependencies m a n a gement • Coco a Pods • Swift P a ck a ge M a n a ger • M a nu a l fr a mework

Slide 20

Slide 20 text

UseCases - Brownfield #2 Android Project Regul a r Android code sh a red (KMP module) a ndroidM a in commonM a in iOSM a in iOS Project Regul a r iOS code Dependencies m a n a gement • Coco a Pods • Swift P a ck a ge M a n a ger • M a nu a l fr a mework a n a lytics (sh a red) Network (sh a red)

Slide 21

Slide 21 text

Adding Multiplatform Mobile to Your Projects • Start small • Keep your shared API simple • Think like a library developer • Implementation should not impact API • Minimise accessibility of everything • Coexist peacefully with (both) platforms

Slide 22

Slide 22 text

Architecture No Silver Bullets

Slide 23

Slide 23 text

Architecture No Silver Bullets Multi-layer Architecture

Slide 24

Slide 24 text

Multi-layer Architecture P r esentation Domain Data

Slide 25

Slide 25 text

Multi-layer Architecture P r esentation • Sharing is possible to a degree • Prefer MVVM and MVI • Decompose, moko-mvvm • Needs experienced team to share

Slide 26

Slide 26 text

Multi-layer Architecture • Perfectly shareable • Services, Models, Gateways Domain

Slide 27

Slide 27 text

Multi-layer Architecture • Usually shareable • Repositories, DTOs and entities • SQLDelight, Realm, Ktor Client, Apollo, kotlinx-datetime Data

Slide 28

Slide 28 text

Multiplatform UI

Slide 29

Slide 29 text

Dependency Injection

Slide 30

Slide 30 text

Ideas, mistakes and learnings

Slide 31

Slide 31 text

Ideas, mistakes and learnings expect fun debugLog(tag: St r ing, message: St r ing) Expect/Actual

Slide 32

Slide 32 text

Ideas, mistakes and learnings expect fun debugLog(tag: St r ing, message: St r ing) Expect/Actual impo r t and r oid.util.Log actual fun debugLog(tag: St r ing, message: St r ing) { Log.d(tag, message) } impo r t platfo r m.Foundation.NSLog actual fun debugLog(tag: St r ing, message: St r ing) { if (Platfo r m.isDebugBina r y) { NSLog("%s: %s", tag, message) } }

Slide 33

Slide 33 text

Ideas, mistakes and learnings inte r nal inte r face XmlFetche r { suspend fun fetchXml(u r l: St r ing) : Pa r se r Input } Interfaces inte r nal class JvmXmlFetche r ( p r ivate val callFacto r y: Call.Facto r y, ) : XmlFetche r { ove r r ide suspend fun fetchXml(u r l: St r ing) : Pa r se r Input { val r equest = c r eateRequest(u r l) r etu r n Pa r se r Input(inputSt r eam = callFacto r y.newCall( r equest).await()) } }

Slide 34

Slide 34 text

Ideas, mistakes and learnings inte r nal inte r face XmlFetche r { suspend fun fetchXml(u r l: St r ing) : Pa r se r Input } Interfaces inte r nal class IosXmlFetche r ( p r ivate val nsU r lSession: NSURLSession, ) : XmlFetche r { ove r r ide suspend fun fetchXml(u r l: St r ing) : Pa r se r Input = suspendCancellableCo r outine { continuation - > . . . } }

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

Gotcha’s •No namespaces •No default parameters •Enums are not Swift-friendly (no values) •Sealed classes are simple classes •Coroutines without cancellation •Flows

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

Make it a team effort

Slide 45

Slide 45 text

Create a library

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

How to publish: Android

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

How to publish: iOS

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

Where to start

Slide 62

Slide 62 text

You have a blank canvas

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

@marcoGomier • Boring code to write multiple times • Code/feature that centralizes the source of truth • Code/feature that can be gradually extracted Where to start?

Slide 65

Slide 65 text

Kotlin multipla tf orm - 🛠 Tooling 📦 Storage 🏗 Architecture 🔑 Crypto 🗃 Serializer - code and tools - 🍎 Compose UI 🧮 Arithmetic - 📋 Log 📱 Device 🔍 Analytics 📁 File ⏰ Date-Time - 🎨 Graphics 🛢 Resources - 🌎 Network 💉 Dependency Injection 🩺 Test 🚀 Language extensions ➿ Asynchronous 🧩 Service SDK 🔧 Utils

Slide 66

Slide 66 text

Kotlin multipla tf orm - 2x faster to develop your features business logic - 2x faster writing unit tests - One tech stack - consistency achieved across pla tf orms conclusions

Slide 67

Slide 67 text

Kotlin multipla tf orm - sta rt small, don’t try to reach 100% of shared logic - be extremely careful with all updates - IDEA, JDK, kotlin, libraries - everything. - keep versioning in mind Suggestions

Slide 68

Slide 68 text

Kotlin multipla tf orm Kotlin Slack Kotlin O ffi cial Kotlin Training Kotlin by: - h tt ps://jakewha rt on.com/presentations/ - h tt p://antonioleiva.com/kotlin Resources Pay attention to this

Slide 69

Slide 69 text

Kotlin multipla tf orm h tt ps://github.com/joreilly/PeopleInSpace h tt ps://github.com/joreilly/ClimateTraceKMP h tt ps://github.com/halcyonmobile/Multipla tf ormPlayground About Kotlin Multipla tf orm project with Swi ft UI, Jetpack Compose, Wear Compose, Compose for Desktop, Compose for Web and Kotlin/JS + React clients along with Ktor backend. Resources

Slide 70

Slide 70 text

• https : //kotlinlang . org/docs/multiplatform . html • https : //kotlinlang . org/docs/native-overview . html • https : //kotlinlang . org/docs/js-overview . html • https : //kotlinlang . org/docs/multiplatform-share-on-platforms . html • https : //kotlinlang . org/docs/multiplatform-connect-to-apis . html • https : //devstreaming-cdn . apple . com/videos/wwdc/2019/416h8485aty341c2/416/416_binary_frameworks_in_swift . pdf • https : //developer . apple . com/videos/play/wwdc2019/416/ • https : //medium . com/@aoriani/list/writing-swiftfriendly-kotlin-multiplatform-apis-c51c2b317fce • https : //kotlinlang . org/docs/native-objc-interop . html • https : //speakerdeck . com/kpgalligan/kotlinconf-2023-kotlin-mobile-multiplatform-for-teams • https : //speakerdeck . com/kpgalligan/sdk-design-and-publishing-for-kotlin-multiplatform-mobile • https : //kotlinlang . org/docs/reference/native/cocoapods . html • https : //kotlinlang . org/docs/multiplatform-build-native-binaries . html#build-xcframeworks • https : //github . com/touchlab/KMMBridge • https : //github . com/prof18/kmp-framework-bundler • https : //github . com/luca992/multiplatform-swiftpackage • https : //github . com/touchlab/xcode-kotlin • https : //github . com/terrakok/kmp-awesome • https : //github . com/AAkira/Kotlin-Multiplatform-Libraries • https : //github . com/touchlab/CrashKiOS • https : //www . droidcon . com/2023/07/31/10-myths-about-crossplatform-mobile-development-with-kotlin/ • https : //blog . jetbrains . com/kotlin/2023/11/kotlin-multiplatform-stable/

Slide 71

Slide 71 text

Thats all folks! https://topmate.io/aditlal 🔗aditlal.dev travelwithadit