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

Accelerate your key learnings of modern Android app development with KMM

Accelerate your key learnings of modern Android app development with KMM

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. Accelerate your key
    learnings of modern
    Android app
    development with
    KMM
    Google Developers

    View Slide

  2. Android GDE

    🛠 Senior Manager Android - Viacom18

    🔊 Speaker

    🌎 Globe Trotter

    🍻 Beer enthusiast
    🎯https:/
    /androiddev.social/@aditlal
    🔗aditlal.dev

    View Slide

  3. View Slide

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

    View Slide

  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

    View Slide

  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

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

  10. View Slide

  11. View Slide

  12. let’s
    fi
    nd a solution that works on all
    platforms.

    View Slide

  13. let’s
    fi
    nd a solution that works on all
    platforms.

    View Slide

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

    View Slide

  15. Cross-platform advantages

    View Slide

  16. Cross-platform advantages
    • smaller team/s
    • typically half of the cost needed on native
    • small learning curve for web developers

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  21. Kotlin
    K
    otlin multiplatform
    Using kotlin in projects to
    target more than one platform

    View Slide

  22. Kotlin multiplatform
    “Shared UI is a history of pain
    and failure. Shared logic is the
    history of computers.”


    - Kevin Galligan

    View Slide

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

    View Slide

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

    View Slide

  25. Kotlin multiplatform

    View Slide

  26. Kotlin multiplatform

    View Slide

  27. Kotlin multiplatform

    View Slide

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

    View Slide

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

    View Slide

  30. Kotlin multiplatform
    Platform specif
    i
    c
    names?

    View Slide

  31. Kotlin multiplatform
    Platform | common

    View Slide

  32. Kotlin multiplatform
    commonMain
    src/commonMain/sample/Platform.kt


    expect object Platform {


    val name: String


    }

    View Slide

  33. Kotlin multiplatform
    src/commonMain/sample/Platform.kt


    expect object Platform {


    val name: String


    }

    View Slide

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

    View Slide

  35. Kotlin multiplatform
    src/androidMain/sample/Platform.kt
    actual object Platform {


    actual val name: String = "Android"


    }
    platform-dependent code

    View Slide

  36. Kotlin multiplatform
    platform-dependent code
    actual object Platform {


    actual val name: String = “iOS"


    }
    src/iOSMain/sample/Platform.kt

    View Slide

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

    View Slide

  38. Kotlin multiplatform
    platform-dependent code
    actual object Platform {


    actual val name: String = “macOS”


    }
    src/macosMain/sample/Platform.kt

    View Slide

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

    View Slide

  40. Kotlin multiplatform

    View Slide

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

    View Slide

  42. Kotlin multiplatform

    View Slide

  43. Kotlin multiplatform

    View Slide

  44. Common

    Kotlin
    Kotlin/JS
    JS code
    Kotlin/JVM
    JVM code
    Kotlin/Native
    Native code
    Kotlin multiplatform

    View Slide

  45. Kotlin multiplatform
    Kotlin
    How much do we share
    Multiplatform
    What makes most sense

    View Slide

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

    View Slide

  47. - 2x faster to develop your features business logic
    - 2x faster writing unit tests
    - One tech stack
    - consistency achieved across platforms
    Kotlin multiplatform conclusions

    View Slide

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

    View Slide

  49. Kotlin multiplatform
    Kotlin Slack
    Kotlin Of
    fi
    cial
    Kotlin Training
    Kotlin by:
    - https://jakewharton.com/presentations/
    - http://antonioleiva.com/kotlin
    Resources

    View Slide

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

    View Slide

  51. AI-powered tooling
    for developers
    •How do I add camera support to
    my app?


    •I want to create a Room
    database.


    •Can you remind me of the
    format for javadocs?


    •What is dark theme?


    •What's the best way to get
    location on Android?

    View Slide

  52. What’s in store for future

    View Slide

  53. What’s in store for future

    View Slide

  54. Predictive Back Gesture
    Introduced in Android 13

    Predictive back gesture supported on phones , large
    screens and foldables.


    BackHandler in Compose

    OnBackPressedCallback | OnBackInvokedCallback

    View Slide

  55. Android design Hub
    https:
    / /
    android
    -
    developers.googleblog.com/2023/05/introducing
    -
    android
    -
    ui
    -
    design
    -
    hub.html


    View Slide

  56. Baseline Pro
    fi
    les improvements
    Performance is key to success in mobile apps.
    Baseline Pro
    fi
    les allow us to partially compile the app at install time, which helps
    get user paths optimized - helps improve runtime performance and launch times.

    View Slide

  57. M3 - Material 3

    View Slide

  58. .. and Much More

    View Slide

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

    View Slide