Slide 1

Slide 1 text

@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

Slide 3

Slide 3 text

@marcogomiero.com bit.ly/kmp-existing-app-workshop

Slide 4

Slide 4 text

@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

Slide 11

Slide 11 text

@marcogomiero.com How it works?

Slide 12

Slide 12 text

@marcogomiero.com shared androidApp iosApp Library Library iOS Android

Slide 13

Slide 13 text

@marcogomiero.com shared androidApp Gradle Module Android Same repository

Slide 14

Slide 14 text

@marcogomiero.com shared androidApp .aar Android Different repositories

Slide 15

Slide 15 text

@marcogomiero.com iosApp iOS shared XCFramework Different repositories Same repository

Slide 16

Slide 16 text

@marcogomiero.com XCFramework https://developer.apple.com/documentation/xcode/creating-a-multi-platform-binary-framework-bundle

Slide 17

Slide 17 text

@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

Slide 20

Slide 20 text

@marcogomiero.com Common Kotlin Android App iOS App .aar XCFramework Android App Repository KMP Repository iOS App Repository Easier for existing projects

Slide 21

Slide 21 text

@marcogomiero.com Code Time 🧑💻

Slide 22

Slide 22 text

@marcogomiero.com XCFramework https://developer.apple.com/documentation/xcode/creating-a-multi-platform-binary-framework-bundle

Slide 23

Slide 23 text

@marcogomiero.com iOS Dependency Managers • CocoaPods • Carthage • Swift Package Manager 💀 💀 ✅

Slide 24

Slide 24 text

@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

Slide 28

Slide 28 text

@marcogomiero.com https://kotlinlang.org/docs/whatsnew21.html#basic-support-for-swift-export

Slide 29

Slide 29 text

@marcogomiero.com Code Time 🧑💻

Slide 30

Slide 30 text

@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

Slide 34

Slide 34 text

Bibliography / Useful Links • https: // docs.github.com/en/actions/publishing-packages/publishing-java-packages-with-gradle • https: // github.com/orgs/community/discussions/26328#discussioncomment-3251485 • https: // github.com/orgs/community/discussions/26634 • https: // developer.apple.com/documentation/xcode/creating-a-multi-platform-binary-framework-bundle • https: // devstreaming-cdn.apple.com/videos/wwdc/2019/416h8485aty341c2/416/416_binary_frameworks_in_swift.pdf • https: // kotlinlang.org/docs/multiplatform-build-native-binaries.html • https: // developer.apple.com/documentation/xcode/distributing-binary-frameworks-as-swift-packages • https: // github.com/rickclephas/KMP-NativeCoroutines • https: // skie.touchlab.co/ • https: // touchlab.co/skie-migration?ti=4B0F129C5D944E54B60B31FE35 • https: // kotlinlang.org/docs/native-objc-interop.html • https: // kotlinlang.org/docs/apple-framework.html • https: // github.com/kotlin-hands-on/kotlin-swift-interopedia • https: // medium.com/@aoriani/list/writing-swiftfriendly-kotlin-multiplatform-apis-c51c2b317fce • https: // blog.devgenius.io/dependancy-management-for-ios-27dd681d7ea0 • https: // github.com/luca992/multiplatform-swiftpackage • https: // touchlab.co/kmmbridge/ • https: // touchlab.co/kmmbridge/spmquickstart • https: // medium.com/geekculture/xcode-13-3-supports-spm-binary-dependency-in-private-github-release-8d60a47d5e45 • https: // touchlab.co/xcodekotlin • https: // kotlinlang.org/docs/native-spm.html#swift-package-distribution • https: // github.com/JetBrains/kotlin/tree/master/docs/swift-export • https: // github.com/Kotlin/swift-export-sample