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 bit.ly/kmp-workshop-devfestberlin

Slide 3

Slide 3 text

@marcoGomier Agenda β€’ Download Android Studio and the Kotlin Multiplatform Plugin β€’ Download Xcode β€’ Quick intro about Kotlin Multiplatform β€’ Start from an Android and iOS native app - that lives in separate repositories β€’ Extract the business logic into a new KMP library β€’ [Manually and locally] Deploy the library β€’ Replace the business logic on Android and iOS with the KMP library β€’ [BONUS] iOS API enhancements β€’ [BONUS] How to deploy in a scalable way

Slide 4

Slide 4 text

@marcoGomier What is Kotlin Multiplatform?

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

@marcoGomier Common Kotlin Kotlin/JVM Kotlin/JS Kotlin/Native JVM Android Browser NodeJS iOS macOS watchOS tvOS Linux Windows Supported Platforms

Slide 9

Slide 9 text

@marcoGomier Common Kotlin Kotlin/JVM Kotlin/JS Kotlin/Native JVM Android Browser NodeJS iOS macOS watchOS tvOS Linux Windows Mobile

Slide 10

Slide 10 text

@marcoGomier How it works?

Slide 11

Slide 11 text

@marcoGomier shared androidApp iosApp Library Library iOS Android

Slide 12

Slide 12 text

@marcoGomier shared androidApp Gradle Module Android Same repository

Slide 13

Slide 13 text

@marcoGomier shared androidApp .aar Android Different repositories

Slide 14

Slide 14 text

@marcoGomier iosApp iOS shared XCFramework Different repositories Same repository

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 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 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

@marcoGomier bit.ly/kmp-existing-workshop

Slide 22

Slide 22 text

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

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 β€’ Configured with a Package.swift file β€’ Based on git β€’ 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 Kotlin -> Obj-c -> Swift

Slide 28

Slide 28 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 29

Slide 29 text

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

Slide 30

Slide 30 text

@marcoGomier Swift Package Manager β€’ Manual is boring and not scalable

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

@marcoGomier Swift Package Manager β€’ Manual is boring and not scalable β€’ Use some tooling and public artifactories

Slide 33

Slide 33 text

@marcoGomier Conclusions β€’ You choose what to share (even UI, if you want) β€’ Validate the process with β€œlittle” effort β€’ Then you can go bigger and share more β€œfeatures”

Slide 34

Slide 34 text

Bibliography / Useful Links β€’ 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: / / github.com/luca992/multiplatform-swiftpackage β€’ https: / / kmmbridge.touchlab.co/ β€’ https: / / medium.com/geekculture/xcode-13-3-supports-spm-binary-dependency-in-private-github- release-8d60a47d5e45

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-devfestberlin