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

What’s New in Kotlin Multiplatform?

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.

Russell Wolf

November 16, 2020
Tweet

More Decks by Russell Wolf

Other Decks in Programming

Transcript

  1. Kotlin is a language for... • Android • JVM (Server,

    Desktop) • JS (Browser, Node) • Native (LLVM, C interop) • iOS (Objective-C Interop)
  2. 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
  3. Kevin Galligan "Shared UI is a history of pain and

    failure. Shared logic is the history of computers."
  4. Common Code // Common
 class Thing(val data: List<String>) { fun

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


    actual val platform = "Android" 
 // iOS
 actual val platform = "iOS"
  6. 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
  7. Community libs • SqlDelight • Multiplatform Settings • Stately •

    Koin, Kodein • More at: • https://github.com/AAkira/Kotlin-Multiplatform-Libraries • https://kotlinlang.org/lp/mobile/ecosystem/
  8. 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