Slide 1

Slide 1 text

Wolfram Rittmeyer Photo by Romain Guy Compose Multiplatform

Slide 2

Slide 2 text

What is Compose „Jetpack Compose is built around composable functions. These functions let you define your app's UI programmatically by describing its shape and data dependencies, rather than focusing on the process of the UI's construction (...)“ https://developer.android.com/jetpack/compose/tutorial

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

https://kotlinlang.org/docs/multiplatform.html

Slide 5

Slide 5 text

Which platforms  Desktop  Android  iOS (beta - well: kind of)  Web (not even in alpha)  Backend

Slide 6

Slide 6 text

https://blog.jetbrains.com/kotlin/2023/05/compose-multiplatform-for-ios-is-in-alpha/

Slide 7

Slide 7 text

https://kotlinlang.org/docs/multiplatform-discover-project.html#compilation-to-a-specific-target

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

Lists of KMP libraries https://github.com/terrakok/kmp-awesome https://github.com/AAkira/Kotlin-Multiplatform-Libraries

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

https://kotlinlang.org/docs/multiplatform-discover-project.html

Slide 15

Slide 15 text

:iosApp:iosApp.swift

Slide 16

Slide 16 text

:composeApp:iosMain:main.kt

Slide 17

Slide 17 text

:composeApp:androidMain:App.android.kt

Slide 18

Slide 18 text

:composeApp:jvmMain:Main.kt

Slide 19

Slide 19 text

expect / actual  Declaration using expect  Implementation using actual

Slide 20

Slide 20 text

expect / actual  Declaration using expect  Implementation using actual  For functions and classes – Other types are in beta  Has to be in the same package – of the respective source sets

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

Interface and DI  Create an interface  Create concrete implementations for platforms  Better for more complex things  Maybe one implementation can be reused – e.g. Android and Desktop

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

Modularization  Maybe the most dangerous part  Use the shared module creator from previous slide only! – Otherwise you get all kind of weird iOS build problems

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

Modularization  Maybe the most dangerous part  Use the shared module creator from previous slide only! – Otherwise you get all kind of weird iOS build problems  Also: You cannot create modules willy-nilly

Slide 31

Slide 31 text

Modularization  Maybe the most dangerous part  Use the shared module creator from previous slide only! – Otherwise you get all kind of weird iOS build problems  Also: You cannot create modules willy-nilly  There is a long doc about this: https://www.jetbrains.com/help/kotlin-multiplatform-dev/multiplatform-project-configuration.html

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

Modularization  Hard to find samples  Good one: TiVi by Chris Banes  Will dig into this some more myself – And provide a repo eventually

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

Kotlin – Swift Interoperability  Translation doesn’t go to Swift but to Objective-C  And only from there to Swift – Type information can get lost (generics with interfaces)

Slide 38

Slide 38 text

Kotlin – Swift Interoperability  Translation doesn’t go to Swift but to Objective-C  And only from there to Swift – Type information can get lost (generics with interfaces)  Coroutines and Flows do not operate as expected

Slide 39

Slide 39 text

Kotlin – Swift Interoperability  Translation doesn’t go to Swift but to Objective-C  And only from there to Swift – Type information can get lost (generics with interfaces)  Coroutines and Flows do not operate as expected – Callbacks – Error handling – Cancelation

Slide 40

Slide 40 text

Kotlin – Swift Interoperability  Libraries to the rescue – KMP-NativeCoroutines https://github.com/rickclephas/KMP-NativeCoroutines – SKIE (Swift Kotlin Interface Enhancer) https://skie.touchlab.co/  See also this article series https://medium.com/@aoriani/list/writing-swiftfriendly-kotlin-multiplatform-apis-c51c2b317fce

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

Resources  unify resources like – images ● vector and bitmap images – strings – files – fonts

Slide 43

Slide 43 text

Resources  follows Android folder conventions – e.g. values-ro for Romanian resources

Slide 44

Slide 44 text

Resources  follows Android folder conventions – e.g. values-ro for Romanian resources  since Compose MP 1.6

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

Testing  UI Testing since Compose MP 1.6  Work the same way as in Android

Slide 49

Slide 49 text

Testing  UI Testing since Compose MP 1.6  Work the same way as in Android  Separating UI testing and logic cumbersome

Slide 50

Slide 50 text

www.wolfram- www.wolfram- rittmeyer.de rittmeyer.de

Slide 51

Slide 51 text

Tooling  A throwback to Compose initial days on Android  Still a bit flaky and susceptible to errors  No UI editor

Slide 52

Slide 52 text

Tooling  You can create previews – But only in Fleet  LayoutInspector works nicely  Also App Inspection – Database Inspector – Network Inspector

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

Configuration  You do not have variants

Slide 55

Slide 55 text

Configuration  You do not have variants  But you can still use some gradle things to help you

Slide 56

Slide 56 text

Configuration  BuildConfig https://github.com/gmazzo/gradle-buildconfig-plugin

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

Configuration  BuildKonfig https://github.com/yshrsmz/BuildKonfig  Seems to be more powerful

Slide 60

Slide 60 text

Configuration  BuildKonfig https://github.com/yshrsmz/BuildKonfig  Seems to be more powerful  Both are around for years  Stars / Forks and number of contributors more or less equal

Slide 61

Slide 61 text

Configuration  BuildKonfig https://github.com/yshrsmz/BuildKonfig  Seems to be more powerful  Both are around for years  Stars / Forks and number of contributors more or less equal  BuildKonfig is on version 0.15.1 while BuildConfig is on 5.3.5

Slide 62

Slide 62 text

Configuration  So with BuildConfig and DI you can do variants yourself

Slide 63

Slide 63 text

Configuration  So with BuildConfig and DI you can do variants yourself  Use Interfaces  Inject proper Class depending on variant

Slide 64

Slide 64 text

Configuration  So with BuildConfig and DI you can do variants yourself  Use Interfaces  Inject proper Class depending on variant  But more cumbersome then what we have on Android

Slide 65

Slide 65 text

https://kotlinlang.org/docs/multiplatform.html#kotlin-multiplatform-use-cases

Slide 66

Slide 66 text

KMP rules  The only proper alternative for – Sharing logic on iOS and Android – While keeping the UI native

Slide 67

Slide 67 text

KMP rules „(…) our initial focus is sharing the business Logic the part of the code that's most agnostic to the user“ What's new in Android, Google I/O https://www.youtube.com/watch?v=_yWxUp86TGg

Slide 68

Slide 68 text

But what about Compose?

Slide 69

Slide 69 text

But what about Compose?  IMHO best suited if – You have a distinct UI – You are a solo dev ● who does not care that much about iOS :-) ● If you care: Use a distinct UI

Slide 70

Slide 70 text

But what about Compose?  IMHO best suited if – You have a distinct UI – You are a solo dev ● who does not care that much about iOS :-) ● If you care: Use a distinct UI – You plan to release no too soon

Slide 71

Slide 71 text

https://flic.kr/p/cXWo83 by Tsahi Levent-Levi

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

Netflix  Ktor Client for networking  SQLDelight for caching „Almost 50% of the production code in our Android and iOS apps is decoupled from the underlying platform“ https://netflixtechblog.com/netflix-android-and-ios-studio-apps-kotlin-multiplatform-d6d4d8d25d23

Slide 74

Slide 74 text

McDonalds  Using it at the repository and use case layer  Networking is still native  They intend to gradually move more areas to shared code https://medium.com/mcdonalds-technical-blog/mobile-multiplatform-development-at-mcdonalds-3b72c8d44ebc

Slide 75

Slide 75 text

Meetup  Apollo Graph QL for backend access  SQLDelight as DB  Repository layer  Interactor / UseCase layer  Koin for DI https://medium.com/making-meetup/adopting-kotlin-multiplatform-mobile-kmm-at-meetup-326b2b0a4186 https://www.youtube.com/watch?v=GtJBS7B3eyM

Slide 76

Slide 76 text

Instabee  Compose Multiplatform  Ktor Client (kotlinx Serialization /kotlinx DateTime)  multiplatform-settings  Compose Cupertino  Voyager for navigation https://medium.com/making-meetup/adopting-kotlin-multiplatform-mobile-kmm-at-meetup-326b2b0a4186 https://www.youtube.com/watch?v=GtJBS7B3eyM

Slide 77

Slide 77 text

Google  At Google I/O 24 Google went all in with KMP  Documentation  Libraries  And more of their own apps using it

Slide 78

Slide 78 text

https://developer.android.com/kotlin/multiplatform

Slide 79

Slide 79 text

https://developer.android.com/kotlin/multiplatform

Slide 80

Slide 80 text

www.wolfram- www.wolfram- rittmeyer.de rittmeyer.de @Rittmeye @Rittmeye

Slide 81

Slide 81 text

Left open  Testing

Slide 82

Slide 82 text

Left open  Testing (e.g. Kotest)

Slide 83

Slide 83 text

Left open  Testing (e.g. Kotest)  Using SwiftUI for certain aspects

Slide 84

Slide 84 text

Left open  Testing (e.g. Kotest)  Using SwiftUI for certain aspects (e.g. navigation)  Integration of Compose MP in an KMP app

Slide 85

Slide 85 text

Left open  Testing (e.g. Kotest)  Using SwiftUI for certain aspects (e.g. navigation)  Integration of Compose MP in an KMP app  expect / actual for Composables

Slide 86

Slide 86 text

Left open  Testing (e.g. Kotest)  Using SwiftUI for certain aspects (e.g. navigation)  Integration of Compose MP in an KMP app  expect / actual for Composables  Debugging Swift-Kotlin integration

Slide 87

Slide 87 text

Left open  Testing (e.g. Kotest)  Using SwiftUI for certain aspects (e.g. navigation)  Integration of Compose MP in an KMP app  expect / actual for Composables  Debugging Swift-Kotlin integration  Use of Cupertino-Style Components

Slide 88

Slide 88 text

https://developer.android.com/jetpack/compose (nowadays a tad different)

Slide 89

Slide 89 text

https://www.linkedin.com/in/wolfram-rittmeyer/ https://www.linkedin.com/in/wolfram-rittmeyer/ https://mastodon.social/@RittmeyerW https://mastodon.social/@RittmeyerW https://www.grokkingandroid.com https://www.grokkingandroid.com https://wolfram-rittmeyer.de/ https://wolfram-rittmeyer.de/ Thanks Picture by Wil Stewart Picture by Wil Stewart

Slide 90

Slide 90 text

Pictures / Licenses 1: Background of title slide shows a small section of a photo by Romain Guy: https://www.flickr.com/photos/romainguy/48539281152 2: Jetpack Compose logo: https://developer.android.com/jetpack/compose 3: Coffee bean and ground coffee by Tamas Pap: https://unsplash.com/photos/brown-and-black-stones-in-close-up-photography-RJPrJQXlmng 4: Cups by Annie Spratt: https://unsplash.com/photos/white-ceramic-mortar-and-pestle-QOBHnWEg-mk 5: Knobs by Adi Goldstein: https://unsplash.com/photos/black-audio-equalizer-HLS7GQ0BCOQ 6: Drawers by Jan Antonin Kolar: https://unsplash.com/photos/brown-wooden-drawer-lRoX0shwjUQ 7: Adapter by Call Me Fred: https://unsplash.com/photos/two-white-power-adapters-on-white-background-nBfTARHPxiU 8: Album by Rirri: https://unsplash.com/photos/photos-on-white-wooden-table-z4KhbVhPP7s 9: Computer / Discussion by Scott Graham: https://unsplash.com/photos/person-holding-pencil-near-laptop-computer-5fNmWej4tAA 10: iOS / Android abomination by Tsahi Levent-Levi: https://unsplash.com/photos/sL2BRR1cuvM 11: Company Spiral by Sven Read: https://unsplash.com/de/fotos/grascale-photo-of-spiral-stairs-8p17jXyfIQQ 12: Investigation by Mediamodifier: https://unsplash.com/de/fotos/black-magnifying-glass-on-white-paper-yx17UuZw1Ck 13: Final Coffee by Fahmi Fakhrudin: https://unsplash.com/photos/person-making-latte-art-nzyzAUsbV0M 14: Slide design "Fedora Photography" by Liam Doherty: https://github.com/dohliam/libreoffice-impress-templates/tree/master/fedora-slideshow/fedora-photography Licenses: 1: Public Domain 2: CC Attribution 2.5 3, 4, 5, 6, 7, 8, 9, 11, 12, 13: Unsplash License 10: CC BY 2.0 DEED 14: MIT License