@marcogomiero.com
Marco Gomiero
Senior Android Engineer @ Airalo
Google Developer Expert for Kotlin
Introducing
Kotlin Multiplatform in
an existing mobile app
workshop edition
Slide 2
Slide 2 text
@marcogomiero.com
Prerequisites
• Download Android Studio and the Kotlin Multiplatform Plugin
• Download Xcode
You can check if your system is ready for Kotlin Multiplatform with
kdoctor: https:
//
github.com/Kotlin/kdoctor
@marcogomiero.com
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
• iOS API enhancements
• How to deploy in a scalable way
Slide 5
Slide 5 text
@marcogomiero.com
What is Kotlin Multiplatform?
Slide 6
Slide 6 text
@marcogomiero.com
“Classic” Cross Platform Solutions
• All-in approach
• Everything is shared, UI included
• Different platforms have different patterns
Slide 7
Slide 7 text
@marcogomiero.com
Kotlin Multiplatform
• Incremental approach
• You choose what to share (even UI, if you want)
Slide 8
Slide 8 text
@marcogomiero.com
Photo by Erwan Hesry on Unsplash
💡 Create a library!
Slide 9
Slide 9 text
@marcogomiero.com
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 10
Slide 10 text
@marcogomiero.com
Common Kotlin
Kotlin/JVM Kotlin/JS
Kotlin/Native
JVM
Android
Browser
NodeJS
iOS
macOS
watchOS
tvOS
Linux
Windows
Mobile
Kotlin/Wasm
Browser
Alpha
@marcogomiero.com
NEW
https://devstreaming-cdn.apple.com/videos/wwdc/2019/416h8485aty341c2/416/416_binary_frameworks_in_swift.pdf
Slide 18
Slide 18 text
@marcogomiero.com https://devstreaming-cdn.apple.com/videos/wwdc/2019/416h8485aty341c2/416/416_binary_frameworks_in_swift.pdf
NEW
iOS mac
OS
watch
OS
tvOS
Slide 19
Slide 19 text
@marcogomiero.com
shared
androidApp iosApp
Gradle
Module
XCFramework
Same Repository
Easier for new projects
@marcogomiero.com
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 25
Slide 25 text
@marcogomiero.com
Code Time 🧑💻
Slide 26
Slide 26 text
@marcogomiero.com
shared
iosApp
Framework
iOS
Kotlin
Objective-C
Swift
->
->
Slide 27
Slide 27 text
@marcogomiero.com
Some gotchas
• No namespaces
• No default parameters
• Enums are not Swift-friendly (no values)
• Sealed classes are simple classes
• Coroutines without cancellation
• Flows
@marcogomiero.com
Swift Package Manager
https://twitter.com/kpgalligan/status/1723364386046173493
Slide 31
Slide 31 text
@marcogomiero.com
Code Time 🧑💻
Slide 32
Slide 32 text
@marcogomiero.com
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 33
Slide 33 text
@marcogomiero.com
Thank you!
Marco Gomiero
Senior Android Engineer @ Airalo
Google Developer Expert for Kotlin
> Twitter: @marcoGomier
> Github: prof18
> Website: marcogomiero.com
> Mastodon: androiddev.social/@marcogom
> BlueSky: @marcogomiero.com