Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

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 Accelerate your key learnings

    of modern Multiplatform app development with KMP Adit Lal GDE Android
  2. Android GDE 🛠 Architect | Entrepreneur 🔊 Speaker 🌎 Globe

    Tro tt er 🍻 Beer enthusiast 🎯https:/ /androiddev.social/@aditlal 🔗aditlal.dev Adit GDE
  3. a wild idea to build develop for An ‣ 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 pla tf orms
  4. native ~2x the team the cost time spent in meetings

    time spent on development time spent on testing time spent on bug fi xing a wild idea to build develop for An
  5. 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 a wild idea to build develop for An and web
  6. 2006 2008 2011 2012 2013 2015 2017 2018 . .

    . . . . . Multipla tf Cross pla tf
  7. Multipla tf orm Cross pla tf orm A system where

    a program targeting multiple platforms utilises platform-speci fi c code alongside shared common code. This setup allows leveraging native functionalities on each platform while maintaining a uni fi ed codebase for shared logic and features. A cross-platform application is a system that enables the deployment of an application using identical application code across different platforms.
  8. 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
  9. Kotlin K otlin multipla tf orm Using kotlin in projects

    to target more than one pla tf orm
  10. Kotlin multipla tf orm “Shared UI is a history of

    pain and failure. Shared logic is the history of computers.” - Kevin Galligan
  11. Kotlin multipla tf orm /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 pla tf orm, based on the popular, modern language kotlin. facilitates non-ui logic availability on many pla tf orms.
  12. Kotlin multipla tf orm Google Workspace Still migrating the Google

    Docs, Slides, Sheets, Drive, and Meet. The existing apps have billions of downloads and Google is in the process of migrating from their in-house J2ObjC transpiler to KMP. Source - https://shorturl.at/xyAPX
  13. Kotlin multipla tf orm Reuse skills Plug and play Control

    your decisions Performance Production-ready Productivity
  14. Kotlin multipla tf orm but how can they expect to

    communicate? expect declared at common module actual declared at android module declared at iOS module declared at ...
  15. Kotlin multipla tf orm 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
  16. Kotlin multipla tf orm pla tf orm-dependent code actual object

    Platform { actual val name: String = “iOS" } src/iOSMain/sample/Platform.kt
  17. Kotlin multipla tf orm src/androidMain/sample/Platform.kt actual object Platform { actual

    val name: String = "Android" } pla tf orm-dependent code actual object Platform { actual val name: String = “iOS" } src/iOSMain/sample/Platform.kt
  18. Kotlin multipla tf orm pla tf orm-dependent code actual object

    Platform { actual val name: String = “macOS” } src/macosMain/sample/Platform.kt
  19. Kotlin multipla tf orm Backend too !! import io.ktor.* fun

    main() { embeddedServer(Netty, 9090) { routing { get("/hello") { call.respondText("Hello, API!") } } }.start(wait = true) } src/jvmMain/kotlin/Server.kt
  20. Kotlin multipla tf orm Common code import io.ktor.client.* import io.ktor.client.request.*

    import io.ktor.client.statement.* class ApiClient { private val client = HttpClient() suspend fun getHello() : String { return client.get("http: / / localhost:9090/hello").bodyAsText() } src/commonMain/kotlin/ApiClient.kt
  21. Kotlin multipla tf orm pla tf orm-dependent code lifecycleScope.launch {

    val response = ApiClient().getHello() / / Update UI with response } src/androidMain/sample/Platform.kt
  22. Kotlin multipla tf orm - strong community - a lot

    of people are using kotlin nowadays - Google and JetBrains are pushing Kotlin exclusively - you can ask questions directly at h tt ps://kotlinlang.slack.com conclusions
  23. 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
  24. 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
  25. 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
  26. 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
  27. 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