Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introducing Kotlin Multiplatform in an existing...

Introducing Kotlin Multiplatform in an existing mobile app - Workshop Edition | DevFest Hamburg

After discovering a new interesting technology or framework, you will probably start asking yourself how to integrate it into an existing project. That's because, the possibility of starting with a blank canvas is rare (not impossible, but rare).

This is also the case for Kotlin Multiplatform, which is getting more and more hype every day. And now, that the technology has become stable, it's the perfect time to start using it! In this hands-on session, we will start with an existing Android and iOS application that "lives" in separate repositories, we will extract the business logic from the Android app and share it between the two apps with a Kotlin Multiplatform library. We will also cover how to distribute the library to the existing applications. By the end of this workshop, you'll have a better understanding of what is needed to start using Kotlin Multiplatform in your existing projects.

Marco Gomiero

October 18, 2024
Tweet

More Decks by Marco Gomiero

Other Decks in Programming

Transcript

  1. @marcoGomier Marco Gomiero Senior Android Developer @ Airalo Google Developer

    Expert for Kotlin Introducing Kotlin Multiplatform in an existing mobile app workshop edition
  2. @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
  3. @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
  4. @marcoGomier “Classic” Cross Platform Solutions • All-in approach • Everything

    is shared, UI included • Different platforms have different patterns
  5. @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
  6. @marcoGomier Common Kotlin Kotlin/JVM Kotlin/JS Kotlin/Native JVM Android Browser NodeJS

    iOS macOS watchOS tvOS Linux Windows Mobile Kotlin/Wasm Browser Alpha
  7. @marcoGomier Common Kotlin Android App iOS App .aar XCFramework Android

    App Repository KMP Repository iOS App Repository Easier for existing projects
  8. @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!
  9. @marcoGomier Some gotchas • No namespaces • No default parameters

    • Enums are not Swift-friendly (no values) • Sealed classes are simple classes • Coroutines without cancellation • Flows
  10. @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”
  11. 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
  12. @marcoGomier Thank you! > Twitter: @marcoGomier > Github: prof18 >

    Website: marcogomiero.com > Mastodon: androiddev.social/@marcogom Marco Gomiero Senior Android Developer @ Airalo Google Developer Expert for Kotlin