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

Accelerate your key learnings of modern Multiplatform app development with KMP

Accelerate your key learnings of modern Multiplatform app development with KMP

Where other technologies abstract away or completely replace platform-specific app development, Kotlin MultiMobile 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 building apps for Android and iOS all in one big repository with a shared domain. We would discuss how to get started, what the future is like, and how to build faster with tips and tricks of the trade.

Adit Lal

May 27, 2023
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

    View full-size slide

  2. Android GDE
    🛠 Architect | Entrepreneur

    🔊 Speaker
    🌎 Globe Tro
    tt
    er
    🍻 Beer enthusiast
    🎯https:/
    /androiddev.social/@aditlal
    🔗aditlal.dev
    Adit
    GDE

    View full-size slide

  3. Android GDE
    🛠 Architect | Entrepreneur

    🔊 Speaer
    🌎 Globe Tro
    tt

    View full-size slide

  4. Let’s Go
    https://app.sli.do/event/mJEpU8mPXKu8n6CDGzeZ35
    or
    Goto slido.com
    Enter 1723179

    View full-size slide

  5. a wild idea to build apps pops!
    develop for Android and iOS

    View full-size slide

  6. 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

    View full-size slide

  7. 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

    View full-size slide

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

    View full-size slide

  9. a wild idea to build apps pops!
    develop for Android and iOS and web

    View full-size slide

  10. 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

    View full-size slide

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

    View full-size slide

  12. let’s
    fi
    nd a solution that works on all
    pla
    tf
    orms.

    View full-size slide

  13. let’s
    fi
    nd a solution that works on all
    pla
    tf
    orms.

    View full-size slide

  14. 2006 2008 2011 2012 2013 2015 2017 2018
    . . . . . . .
    Multipla
    tf
    Cross pla
    tf

    View full-size slide

  15. 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.

    View full-size slide

  16. how do we have the best of

    both worlds?

    View full-size slide

  17. how do we have the best of

    both worlds?

    View full-size slide

  18. 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

    View full-size slide

  19. Kotlin
    K
    otlin multipla
    tf
    orm
    Using kotlin in projects to
    target more than one
    pla
    tf
    orm

    View full-size slide

  20. Kotlin multipla
    tf
    orm
    “Shared UI is a history of pain
    and failure. Shared logic is the
    history of computers.”
    - Kevin Galligan

    View full-size slide

  21. Kotlin multipla
    tf
    Source - https://shorturl.at/xyAPX

    View full-size slide

  22. 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.

    View full-size slide

  23. 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

    View full-size slide

  24. Kotlin multipla
    tf
    orm
    Reuse skills
    Plug and play
    Control your decisions
    Performance
    Production-ready
    Productivity

    View full-size slide

  25. Kotlin multipla
    tf
    orm

    View full-size slide

  26. Kotlin multipla
    tf
    orm

    View full-size slide

  27. Kotlin multipla
    tf
    orm

    View full-size slide

  28. Kotlin multipla
    tf
    orm

    View full-size slide

  29. Kotlin multipla
    tf
    orm
    but how can they expect to communicate?

    View full-size slide

  30. 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 ...

    View full-size slide

  31. Kotlin multipla
    tf
    orm
    Platform specif
    i
    c
    names?

    View full-size slide

  32. Kotlin multipla
    tf
    orm
    Pla
    tf
    orm | common

    View full-size slide

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

    View full-size slide

  34. Kotlin multipla
    tf
    orm
    src/commonMain/sample/Platform.kt
    expect object Platform {
    val name: String
    }

    View full-size slide

  35. 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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  38. 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

    View full-size slide

  39. Kotlin multipla
    tf
    orm
    pla
    tf
    orm-dependent code
    actual object Platform {
    actual val name: String = “macOS”
    }
    src/macosMain/sample/Platform.kt

    View full-size slide

  40. 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

    View full-size slide

  41. 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

    View full-size slide

  42. Kotlin multipla
    tf
    orm
    pla
    tf
    orm-dependent code
    lifecycleScope.launch {
    val response = ApiClient().getHello()
    / /
    Update UI with response
    }
    src/androidMain/sample/Platform.kt

    View full-size slide

  43. Kotlin multipla
    tf
    orm

    View full-size slide

  44. Kotlin multipla
    tf
    orm
    Actual needs to match
    because obviously it does

    View full-size slide

  45. Kotlin multipla
    tf
    orm

    View full-size slide

  46. Kotlin multipla
    tf
    orm

    View full-size slide

  47. Common
    Kotlin
    Kotlin/JS
    JS code
    Kotlin/JVM
    JVM code
    Kotlin/Native
    Native code
    Kotlin multipla
    tf
    orm

    View full-size slide

  48. Kotlin multipla
    tf
    orm
    How much do we share
    Multipla
    tf
    orm

    What makes most sense

    View full-size slide

  49. 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

    View full-size slide

  50. 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

    View full-size slide

  51. 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

    View full-size slide

  52. 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

    View full-size slide

  53. 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

    View full-size slide

  54. 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

    View full-size slide

  55. Thats all folks!
    https:/
    /linktr.ee/aldefy

    View full-size slide