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

A hitchhiker's guide to Kotlin MultiPlatform

Adit Lal
November 26, 2022

A hitchhiker's guide to Kotlin MultiPlatform

Where other technologies abstract away or completely replace platform-specific app development, Kotlin Multiplatform is complementary to existing platform-specific technologies and is geared towards replacing platform-agnostic business logic. It’s a new tool in the toolbox as opposed to replacing the toolbox, this talk would take you on a hitch-hiking journey across multiple platforms such as web , desktop and mobile apps all using KMP. We would pickup on where to get started , whats the future like and how to build faster with tips and tricks of the trade.

Adit Lal

November 26, 2022
Tweet

More Decks by Adit Lal

Other Decks in Programming

Transcript

  1. A hitchhiker's guide to Kotlin MultiPlatform Google Developers

  2. Android GDE
 🛠 Individual Consultant
 🔊 Speaker
 🌎 Globe Trotter


    🍻 Beer enthusiast 🎯https:/ /androiddev.social/@aditlal 🔗aditlal.dev
  3. None
  4. a wild idea to build apps pops! develop for Android

    and iOS
  5. ‣ hire a team - Android and iOS ‣ de

    fi ne requirements ‣ plan roadmap for development ‣ develop and maintain and test apps ‣ production validation ‣ cross-check parity among both platforms
  6. native ~2x the team the cost time spent in meetings

    time spent on development time spent on testing time spent on bug fi xing
  7. a wild idea to build apps pops! develop for Android

    and iOS
  8. a wild idea to build apps pops! and web develop

    for Android and iOS
  9. native + web ~3x the team the cost time spent

    in meetings time spent on development time spent on testing time spent on bug fi xing
  10. None
  11. None
  12. let’s fi nd a solution that works on all platforms.

  13. 2006 2008 2011 2012 2013 2015 2017 2018 . .

    . . . . .
  14. Cross-platform advantages

  15. Cross-platform advantages • smaller team/s • typically half of the

    cost needed on native • small learning curve for web developers
  16. Cross-platform advantages dis • Locked to the framework implementation of

    UI - new updates from the OS will take time to adapt • performance is not on par to native • One may end up also writing native code alongside • OS / device features are dependent on the fw support
  17. how do we have the best of both worlds?

  18. how do we have the best of both worlds?

  19. Kotlin • developed by JetBrains • open source • concise,

    safe, interoperable, dev tool-friendly • Supported/used by Google for Android Development • It is so much more than “just for Android”
  20. Kotlin K otlin multiplatform Using kotlin in projects to target

    more than one platform
  21. Kotlin multiplatform “Shared UI is a history of pain and

    failure. Shared logic is the history of computers.”
 
 - Kevin Galligan
  22. Kotlin multiplatform - language features - kotlin fi rst! -

    low risk - you decide what’s worth to share across projects - interoperability - consistency across platforms - strong community support
  23. Kotlin multiplatform /kot · lin mul · ti · plat

    · form / / kät' lin malti' platfôrm, kät'lin melti'platfôrm/ noun optional, natively-integrated, open-source, code sharing platform, based on the popular, modern language kotlin. facilitates non-ui logic availability on many platforms.
  24. Kotlin multiplatform

  25. Kotlin multiplatform

  26. Kotlin multiplatform

  27. Kotlin multiplatform but how can they expect to communicate?

  28. Kotlin multiplatform but how can they expect to communicate? expect

    declared at common module 
 actual declared at android module declared at iOS module declared at ...
  29. Kotlin multiplatform Platform specif i c names?

  30. Kotlin multiplatform Platform | common

  31. Kotlin multiplatform commonMain src/commonMain/sample/Platform.kt expect object Platform { val name:

    String }
  32. Kotlin multiplatform src/commonMain/sample/Platform.kt expect object Platform { val name: String

    }
  33. Kotlin multiplatform src/commonMain/sample/Platform.kt expect object Platform { val name: String

    } targets: android and iOS or macOS
 de fi ne actual on android de fi ne actual on iOS
 de fi ne actual on macOS
  34. Kotlin multiplatform src/androidMain/sample/Platform.kt actual object Platform { actual val name:

    String = "Android" } platform-dependent code
  35. Kotlin multiplatform platform-dependent code actual object Platform { actual val

    name: String = “iOS" } src/iOSMain/sample/Platform.kt
  36. Kotlin multiplatform src/androidMain/sample/Platform.kt actual object Platform { actual val name:

    String = "Android" } platform-dependent code actual object Platform { actual val name: String = “iOS" } src/iOSMain/sample/Platform.kt
  37. Kotlin multiplatform platform-dependent code actual object Platform { actual val

    name: String = “macOS” } src/macosMain/sample/Platform.kt
  38. Kotlin multiplatform platform-dependent code import io.ktor.* fun main() { embeddedServer(Netty,

    9090) { routing { get("/hello") { call.respondText("Hello, API!") } } }.start(wait = true) } src/jvmMain/kotlin/Server.kt
  39. Kotlin multiplatform

  40. Kotlin multiplatform Actual needs to match because obviously it does

  41. Kotlin multiplatform

  42. Kotlin multiplatform

  43. Common
 Kotlin Kotlin/JS JS code Kotlin/JVM JVM code Kotlin/Native Native

    code Kotlin multiplatform
  44. Kotlin multiplatform Kotlin How much do we share Multiplatform What

    makes most sense
  45. Kotlin multiplatform - strong community - a lot of people

    are using kotlin nowadays - Google and JetBrains are pushing Kotlin exclusively - you can ask questions directly at https://kotlinlang.slack.com conclusions
  46. Kotlin multiplatform - 2x faster to develop your features business

    logic - 2x faster writing unit tests - One tech stack - consistency achieved across platforms conclusions
  47. Kotlin multiplatform - start 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
  48. Kotlin multiplatform Kotlin Slack Kotlin Of fi cial Kotlin Training

    Kotlin by: - https://jakewharton.com/presentations/ - http://antonioleiva.com/kotlin Resources
  49. Kotlin multiplatform https://github.com/joreilly/PeopleInSpace
 
 About Kotlin Multiplatform project with SwiftUI,

    Jetpack Compose, Wear Compose, Compose for Desktop, Compose for Web and Kotlin/JS + React clients along with Ktor backend. Resources
  50. Thats all folks! https://cal.com/adit/30min 🎯https:/ /androiddev.social/@aditlal 🔗aditlal.dev