Slide 1

Slide 1 text

πŸ‘¨πŸ’» Senior Android Developer @ Airalo Google Developer Expert for Kotlin Marco Gomiero @marcoGomier 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 β€’ 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 3

Slide 3 text

@marcoGomier bit.ly/kmp-existing-app-workshop

Slide 4

Slide 4 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 5

Slide 5 text

@marcoGomier What is Kotlin Multiplatform?

Slide 6

Slide 6 text

@marcoGomier β€œClassic” Cross Platform Solutions β€’ All-in approach β€’ Everything is shared, UI included β€’ Different platforms have different patterns

Slide 7

Slide 7 text

@marcoGomier Kotlin Multiplatform β€’ Incremental approach β€’ You choose what to share (even UI, if you want)

Slide 8

Slide 8 text

@marcoGomier Photo by Erwan Hesry on Unsplash πŸ’‘ Create a library!

Slide 9

Slide 9 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 10

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

Slide 11

Slide 11 text

@marcoGomier How it works?

Slide 12

Slide 12 text

@marcoGomier shared androidApp iosApp Library Library iOS Android

Slide 13

Slide 13 text

@marcoGomier shared androidApp Gradle Module Android Same repository

Slide 14

Slide 14 text

@marcoGomier shared androidApp .aar Android Different repositories

Slide 15

Slide 15 text

@marcoGomier iosApp iOS shared XCFramework Different repositories Same repository

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

@marcoGomier NEW https://devstreaming-cdn.apple.com/videos/wwdc/2019/416h8485aty341c2/416/416_binary_frameworks_in_swift.pdf

Slide 18

Slide 18 text

@marcoGomier 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

@marcoGomier shared androidApp iosApp Gradle Module XCFramework Same Repository Easier for new projects

Slide 20

Slide 20 text

@marcoGomier 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

@marcoGomier Code Time πŸ§‘πŸ’»

Slide 22

Slide 22 text

@marcoGomier bit.ly/kmp-existing-workshop

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

@marcoGomier iOS Dependency Managers β€’ CocoaPods β€’ Carthage β€’ Swift Package Manager πŸ’€ πŸ’€ βœ…

Slide 25

Slide 25 text

@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 26

Slide 26 text

@marcoGomier Code Time πŸ§‘πŸ’»

Slide 27

Slide 27 text

@marcoGomier Swift Package Manager https://twitter.com/kpgalligan/status/1723364386046173493

Slide 28

Slide 28 text

@marcoGomier Code Time πŸ§‘πŸ’»

Slide 29

Slide 29 text

@marcoGomier shared iosApp Framework iOS Kotlin Objective-C Swift -> ->

Slide 30

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

Slide 31

Slide 31 text

@marcoGomier Code Time πŸ§‘πŸ’»

Slide 32

Slide 32 text

@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 33

Slide 33 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: // kmmbridge.touchlab.co/ β€’ https: // touchlab.co/kmmbridge-quick-start β€’ 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

Slide 34

Slide 34 text

@marcoGomier

Slide 35

Slide 35 text

@marcoGomier Thank you! > Twitter: @marcoGomier > Github: prof18 > Website: marcogomiero.com > Mastodon: androiddev.social/@marcogom πŸ‘¨πŸ’» Senior Android Developer @ Airalo Google Developer Expert for Kotlin Marco Gomiero bit.ly/kmp-workshop-feedback