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

KMP in Practice: Real world case studies

KMP in Practice: Real world case studies

In this session we will delve into Kotlin Multiplatform (KMP) and explore its real world applications and case studies. Participants will have the opportunity to learn from developers who have successfully incorporated KMP into their projects across platforms like JVM, Android, iOS and Web. The discussion will cover the following topics;

*Successful Implementations; We will provide walkthroughs of how KMP has been effectively used in various sectors such as finance, healthcare and entertainment. Specifically we will showcase an entertainment app called JioCinema that utilizes KMP.

*Overcoming Challenges; Gain insights into obstacles faced during KMP implementation including platform specific integration issues, performance optimization and maintaining code quality across different platforms. We'll discuss solutions and workarounds that have been employed.

*Performance Metrics; Analyze the performance enhancements achieved through KMP by presenting numbers and metrics obtained from real case studies.

*Best Practices; Take away key insights and best practices for developers who are considering adopting KMP. This includes information on code sharing strategies testing methodologies and deployment approaches.

*Future Potential; Explore the evolving landscape of KMP and its impact on the future of cross platform development.

This session is designed for Kotlin developers with to advanced skills who are interested, in multiplatform development.

This event aims to provide attendees with insights and practical knowledge on how to effectively implement KMP in their own projects. It will showcase the potential of KMP to streamline development processes and improve app performance, across platforms.

Adit Lal

July 06, 2024
Tweet

More Decks by Adit Lal

Other Decks in Technology

Transcript

  1. Adit Lal | 2024 Journey of ups/downs for the real-world

    KMP apps KMP in Practice: Real world case studies
  2. 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
  3. • 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
  4. 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)
  5. UseCases - Greenfield #2 a ndroidApp (module) iosApp (module) a

    n a lytics (sh a red) Network (sh a red)
  6. 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
  7. 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)
  8. 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
  9. Multi-layer Architecture P r esentation • Sharing is possible to

    a degree • Prefer MVVM and MVI • Decompose, moko-mvvm • Needs experienced team to share
  10. Multi-layer Architecture • Usually shareable • Repositories, DTOs and entities

    • SQLDelight, Realm, Ktor Client, Apollo, kotlinx-datetime Data
  11. 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) } }
  12. 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()) } }
  13. 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 - > . . . } }
  14. Gotcha’s •No namespaces •No default parameters •Enums are not Swift-friendly

    (no values) •Sealed classes are simple classes •Coroutines without cancellation •Flows
  15. @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?
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. • 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/