@marcoGomier
Marco Gomiero
Senior Android Developer @ Airalo
Google Developer Expert for Kotlin
Introducing
Kotlin Multiplatform in
an existing mobile app
workshop edition
Slide 2
Slide 2 text
@marcoGomier
Prerequisites
• Download Android Studio and the Kotlin Multiplatform Plugin*
Slide 3
Slide 3 text
@marcoGomier
Prerequisites
• Download Android Studio and the Kotlin Multiplatform Plugin*
* Might not work with Android Studio Koala Feature Drop 2024.1.2.
if so, use terrakok.github.io/kmp-web-wizard/
Slide 4
Slide 4 text
@marcoGomier
Prerequisites
• Download Android Studio and the Kotlin Multiplatform Plugin
• Download Xcode
• A valid GitHub account.
You can check if your system is ready for Kotlin Multiplatform with
kdoctor: https:
//
github.com/Kotlin/kdoctor
Slide 5
Slide 5 text
@marcoGomier
bit.ly/kmp-existing-app-workshop
Slide 6
Slide 6 text
@marcoGomier
Agenda
• Quick intro about Kotlin Multiplatform
• Start from an Android and iOS native app - that lives in separate repositories and
extract the business logic from Android into a new KMP library
• Deploy the library on Android
• Break ☕
• Deploy the library on iOS
• How to deploy in a scalable way
• iOS API enhancements
Slide 7
Slide 7 text
@marcoGomier
What is Kotlin Multiplatform?
Slide 8
Slide 8 text
@marcoGomier
“Classic” Cross Platform Solutions
• All-in approach
• Everything is shared, UI included
• Different platforms have different patterns
Slide 9
Slide 9 text
@marcoGomier
Kotlin Multiplatform
• Incremental approach
• You choose what to share (even UI, if you want)
Slide 10
Slide 10 text
@marcoGomier
Photo by Erwan Hesry on Unsplash
💡 Create a library!
Slide 11
Slide 11 text
@marcoGomier
Common Kotlin
Kotlin/JVM Kotlin/JS
Kotlin/Native
JVM
Android
Browser
NodeJS
iOS
macOS
watchOS
tvOS
Linux
Windows
Supported Platforms
Kotlin/Wasm
Browser
Alpha
Slide 12
Slide 12 text
@marcoGomier
Common Kotlin
Kotlin/JVM Kotlin/JS
Kotlin/Native
JVM
Android
Browser
NodeJS
iOS
macOS
watchOS
tvOS
Linux
Windows
Mobile
Kotlin/Wasm
Browser
Alpha
@marcoGomier
Swift Package Manager
• Based on git
• Configured with a Package.swift file
• Semantic versioning (e.g. 1.2.3) with git tags
• Can contain code or binaries
• Can be local or remote, it’s git!
Slide 28
Slide 28 text
@marcoGomier
Code Time 🧑💻
Slide 29
Slide 29 text
@marcoGomier
Swift Package Manager
https://twitter.com/kpgalligan/status/1723364386046173493
Slide 30
Slide 30 text
@marcoGomier
Code Time 🧑💻
Slide 31
Slide 31 text
@marcoGomier
shared
iosApp
Framework
iOS
Kotlin
Objective-C
Swift
->
->
Slide 32
Slide 32 text
@marcoGomier
Some gotchas
• No namespaces
• No default parameters
• Enums are not Swift-friendly (no values)
• Sealed classes are simple classes
• Coroutines without cancellation
• Flows
@marcoGomier
Conclusions
• You choose what to share (even UI, if you want)
• Validate the process with “little” effort
• Find the best (for you) approach/infrastructure
• Then you can go bigger and share more “features”
Slide 36
Slide 36 text
@marcoGomier https://touchlab.co/kmp-teams-use-source
More reading