What’s New in Kotlin Multiplatform?

7edddae207b212e5e035133d9eb10b82?s=47 Russell Wolf
November 16, 2020

What’s New in Kotlin Multiplatform?

What do I need to do to set up a Multiplatform Kotlin app? The answer looks different today than it did two years ago. Many tutorials and samples you find online are out of date, and there’s lots of conflicting advice about how to configure things. With Kotlin 1.4 recently released, it’s a great time to take stock of where things are, and what things you might want to change compared to a year or two ago.

Drawing on questions I’ve seen from the community and in consulting work, as well as my experience building one of the early Kotlin Multiplatform libraries, I’ll catalogue some useful tips and tricks for Multiplatform projects. We’ll talk about common pitfalls and useful tools and examples. Whether you’re maintaining a project that’s starting to show its age, or you’re just getting started, we’ll get you up-to-speed on the latest advice.

7edddae207b212e5e035133d9eb10b82?s=128

Russell Wolf

November 16, 2020
Tweet

Transcript

  1. @RussHWolf ( or ) What's New in Kotlin Multiplatform Droidcon

    Americas 2020 Russell Wolf
  2. None
  3. Kotlin is a language for... • Android • JVM (Server,

    Desktop) • JS (Browser, Node) • Native (LLVM, C interop) • iOS (Objective-C Interop)
  4. Kotlin Multiplatform • Common code compiles to multiple targets •

    Platform-specific code can interop with that platform • Flexible - share only what makes sense to your use-case
  5. Kevin Galligan "Shared UI is a history of pain and

    failure. Shared logic is the history of computers."
  6. Mobile is the killer app for Kotlin Multiplatform

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

  8. MPP KMP
 KMM

  9. Shared Code

  10. Shared Code Android Common iOS

  11. Shared Code Android Common iOS

  12. Shared Code Android Common iOS

  13. Shared Code Android Common iOS

  14. Shared Code Android Common iOS

  15. Shared Code Android Common iOS

  16. Shared Code Android Common iOS

  17. Architecture

  18. Common iOS Framework Android AAR Architecture

  19. Common iOS Framework Android AAR Android App iOS App Architecture

  20. ... ... Common iOS Framework Android AAR Android App iOS

    App Architecture
  21. Common iOS Framework Android AAR ... ... Android App iOS

    App ... Architecture
  22. Multiplatform Code

  23. Common Code // Common
 class Thing(val data: List<String>) { fun

    doSomething() { data.forEach { println(it) } } }
  24. Platform-Specific Code // Common
 expect val platform: String
 // Android


    actual val platform = "Android" 
 // iOS
 actual val platform = "iOS"
  25. Platform-Specific Code // Common
 interface Logger { fun log(message: String)

    }
 // Android
 class AndroidLogger : Logger { ... }
 // iOS - Kotlin
 class IosLogger { ... }
 // iOS - Swift class SwiftLogger : Logger { ... } // Common
 class TestLogger : Logger
  26. So What's New?

  27. Docs!

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

  29. https://kotlinlang.org/docs/mobile

  30. https://kotlinlang.org/docs/reference/mpp-intro.html

  31. Tooling

  32. KMM Android Studio Plugin

  33. Xcode Kotlin Plugin https://github.com/touchlab/xcode-kotlin

  34. IDEA Project Wizard

  35. Heirarchical Project Structure and Gradle Metadata

  36. Heirarchical Project Structure kotlin.mpp.enableGranularSourceSetsMetadata=true
 kotlin.native.enableDependencyPropagation=false

  37. Threading

  38. Kotlin/Native Threading

  39. Libraries

  40. kotlinx-coroutines https://github.com/Kotlin/kotlinx.coroutines • Suspend functions and Flows • Separate single-threaded

    and multithreaded versions • 1.3.9 vs 1.3.9-native-mt
  41. ktor https://github.com/ktorio/ktor • Http client • Uses native-mt coroutines version

  42. kotlinx-serialization https://github.com/Kotlin/kotlinx.serialization • Multi-format serialization • First stable release! •

    API changes • New docs
  43. kotlinx-datetime https://github.com/Kotlin/kotlinx-datetime • New! • Small API surface • Report

    issues and use-cases
  44. Jetpack Compose?

  45. Community libs • SqlDelight • Multiplatform Settings • Stately •

    Koin, Kodein • More at: • https://github.com/AAkira/Kotlin-Multiplatform-Libraries • https://kotlinlang.org/lp/mobile/ecosystem/
  46. Samples

  47. KaMPKit https://github.com/touchlab/KaMPKit

  48. https://github.com/joreilly/PeopleInSpace https://github.com/joreilly/BikeShare

  49. https://github.com/russhwolf/multiplatform-hello

  50. ... and more

  51. Resources • KMM Portal: https://kotlinlang.org/lp/mobile/ • KMM Docs: https://kotlinlang.org/docs/mobile/samples.html •

    Multiplatform Docs: https://kotlinlang.org/docs/reference/mpp-intro.html • Codelabs: https://play.kotlinlang.org/hands-on/overview • Roadmap: https://kotlinlang.org/roadmap.html • KaMPKit: https://github.com/touchlab/KaMPKit
  52. @RussHWolf ( or ) Questions? Russell Wolf