Slide 1

Slide 1 text

Wolfram Rittmeyer Photo by Romain Guy Compose Multiplatform Produktiv geeignet?

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

Zielplattformen  Desktop  Android  iOS (beta)  Web (alpha)

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Listen von KMP libraries https://github.com/terrakok/kmp-awesome https://github.com/AAkira/Kotlin-Multiplatform-Libraries Oder per gezielter Suche: https://klibs.io

Slide 10

Slide 10 text

Icons https://composeicons.com

Slide 11

Slide 11 text

Icons  App Icon Plugin  Erzeugt aus einem Icon App Icons für iOS und Android  Vorlage: PNG oder SVG https://github.com/qamarelsafadi/KMPAppIconGeneratorPlugin

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

:iosApp:iosApp.swift

Slide 15

Slide 15 text

:composeApp:iosMain:main.kt

Slide 16

Slide 16 text

:composeApp:androidMain:App.android.kt

Slide 17

Slide 17 text

:composeApp:jvmMain:Main.kt

Slide 18

Slide 18 text

expect / actual  Deklaration mit expect  Implementation mit actual

Slide 19

Slide 19 text

expect / actual  Deklaration mit expect  Implementation mit actual  Für Funktionen, Objekte, Enums und Properties – Für Klassen in Beta  Müssen im gleichen Package liegen – In den jeweiligen Sourcesets

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

Interfaces mit DI  Erzeuge ein Interface  Implementiere entsprechend je nach Plattform  Besser für komplexe Dinge  Zudem Teilen von Implementierung – z.B. Android und Desktop

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

Ressourcen  Gemeinsamer Ressourcenzugriff auf – Bilder ● Vektor- und Bitmap-Images – Texte – Dateien – Schriftarten

Slide 25

Slide 25 text

Ressourcen  Folgt den Android-Konventionen – Bspw. values-de for deutsche Ressourcen

Slide 26

Slide 26 text

Ressourcen  Folgt den Android-Konventionen – Bspw. values-de for deutsche Ressourcen  Erst seit Compose MP 1.6

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

Ressourcen  Für jedes Modul möglich  gradle-Task generateBuildConfig – Bei jeder Änderung aufzurufen

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

Tests  UI Tests seit Compose MP 1.6 möglich  Analog zu Android Compose Tests

Slide 32

Slide 32 text

Tests  UI Tests seit Compose MP 1.6 möglich  Analog zu Android Compose Tests  Logik-Tests mit Junit und Ui-Tests zugleich problemlos  Kotest-Test hingegen nur mit Task jvmTest möglich

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

Modularisierung  Potenziell gefährlich  Module nur mit Plugin erzeugen! – Sonst ggf. Probleme bei iOS-Build

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

Modularisierung  Zudem kann man Module nicht beliebig anlegen

Slide 40

Slide 40 text

Modularisierung  Zudem kann man Module nicht beliebig anlegen  Dazu gibt es eine ziemlich lange Doku: https://www.jetbrains.com/help/kotlin-multiplatform-dev/multiplatform-project-configuration.html

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

Modularisierung  Kaum Sample-Apps  Empfehlenswert: TiVi by Chris Banes

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

Konfiguration  Es gibt keine Variants wie bei Android

Slide 47

Slide 47 text

Konfiguration  Es gibt keine Variants wie bei Android  Aber gradle-basierte Workarounds

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

Konfiguration  BuildKonfig https://github.com/yshrsmz/BuildKonfig  Macht einen sehr guten Eindruck

Slide 52

Slide 52 text

Konfiguration  BuildKonfig https://github.com/yshrsmz/BuildKonfig  Macht einen sehr guten Eindruck  Unterstützt Flavors (mittels Properties) – gradle.properties oder – ./gradlew build -Pbuildkonfig.flavor=release

Slide 53

Slide 53 text

Konfiguration  Beide absolut vergleichbar – Alter, Beitragende, Github Forks- und Stars

Slide 54

Slide 54 text

Konfiguration  Beide absolut vergleichbar – Alter, Beitragende, Github Forks- und Stars – Abweichung in Versioning-Policy ● BuildKonfig nutzt 0.15.1, BuildConfig hingegen 5.3.5

Slide 55

Slide 55 text

Konfiguration  Mit BuildConfig/BuildKonfig + DI eigene Varianten

Slide 56

Slide 56 text

Konfiguration  Mit BuildConfig/BuildKonfig + DI eigene Varianten  Mit Interfaces  Und Injektion der Implementierung je nach Variante

Slide 57

Slide 57 text

Konfiguration  Mit BuildConfig/BuildKonfig + DI eigene Varianten  Mit Interfaces  Und Injektion der Implementierung je nach Variante  Anderes Handling aber mehr Übersicht

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

Kotlin – Swift Zusammenspiel  Compilation nicht zu Swift sondern zu Objective-C  Von da dann nutzbar von Swift aus – Typinformationen können verloren gehen (Generics mit Interfaces)

Slide 60

Slide 60 text

Kotlin – Swift Zusammenspiel  Compilation nicht zu Swift sondern zu Objective-C  Von da dann nutzbar von Swift aus – Typinformationen können verloren gehen (Generics mit Interfaces)  Coroutinen und Flows funktionieren nicht wie erwartet

Slide 61

Slide 61 text

Kotlin – Swift Zusammenspiel  Compilation nicht zu Swift sondern zu Objective-C  Von da dann nutzbar von Swift aus – Typinformationen können verloren gehen (Generics mit Interfaces)  Coroutinen und Flows funktionieren nicht wie erwartet – Callbacks – Error Handling – Cancelation

Slide 62

Slide 62 text

Kotlin – Swift Zusammenspiel  Zum Glück gibt es Bibliotheken / Plugins – KMP-NativeCoroutines https://github.com/rickclephas/KMP-NativeCoroutines – SKIE (Swift Kotlin Interface Enhancer) https://skie.touchlab.co/  Sehr gute Artikelserie https://medium.com/@aoriani/list/writing-swiftfriendly-kotlin-multiplatform-apis-c51c2b317fce

Slide 63

Slide 63 text

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

Slide 64

Slide 64 text

Tooling  Wie früher als Compose bei Android neu war  Alles noch ein wenig wackelig  Kein UI Editor

Slide 65

Slide 65 text

Tooling  Previews sind möglich – Aber nur in Fleet  LayoutInspector funktioniert wie immer  App Inspection funktioniert ebenso wie immer – Database Inspector – Network Inspector

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

KMP rules  Die einzige Option um – Logik zwischen iOS und Android zu teilen – Aber eine native UI zu behalten

Slide 68

Slide 68 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 69

Slide 69 text

Aber was ist mit Compose?

Slide 70

Slide 70 text

Aber was ist mit Compose?  Besonders dann geeignet wenn – Deine App eine eigenständige UI hat ● Zumindest für Teile der App – Oder Du ein Solo-Dev bist ● Dem iOS aber nicht so wichtig ist :-) ● Oder wenn doch: Der eine eigenständige UI nutzt

Slide 71

Slide 71 text

Aber was ist mit Compose?  Besonders dann geeignet wenn – Deine App eine eigenständige UI hat ● Zumindest für Teile der App – Oder Du ein Solo-Dev bist ● Dem iOS aber nicht so wichtig ist :-) ● Oder wenn doch: Der eine eigenständige UI nutzt – Deine App noch nicht bald released wird

Slide 72

Slide 72 text

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

Slide 73

Slide 73 text

Libs als Hilfe  compose-cupertino – Wrapper für alle Komponenten – AdaptiveTopAppBar, AdaptiveNavigationBar...  Calf (Compose Adaptive Look & Feel) – gute Lösung vor allem für kritische Komponenten – Zum Beispiel Dialoge, Datepicker...

Slide 74

Slide 74 text

Aber dennoch „It looks awfully similar, but it’s not the same. Sometimes imitation is so good that your user is not aware of the problem. However the user’s dog is not fooled and will bark at these buttons, because they’re just not quite right.“ https://ericsink.com/bos/Platforms.html

Slide 75

Slide 75 text

Aber dennoch „In fact, if we’re going to participate in platform decisions as geeks with a touch of business clue, there is only one concept we have to learn: It's all about the user.“ https://ericsink.com/bos/Platforms.html

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

Netflix  Ktor Client für Netzwerkzugriff  SQLDelight zum Cachen „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 78

Slide 78 text

McDonalds  Nutzt KMP im Repository und im Usecase Layer  Netzwerkzugriff noch nativ  Planen, KMP-Bereich mehr und mehr auszuweiten https://medium.com/mcdonalds-technical-blog/mobile-multiplatform-development-at-mcdonalds-3b72c8d44ebc

Slide 79

Slide 79 text

Meetup  Apollo Graph QL für den Backend-Zugriff  SQLDelight als DB  Repository Layer  Interactor / UseCase Layer  Koin für DI https://medium.com/making-meetup/adopting-kotlin-multiplatform-mobile-kmm-at-meetup-326b2b0a4186 https://www.youtube.com/watch?v=GtJBS7B3eyM

Slide 80

Slide 80 text

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

Slide 81

Slide 81 text

Google  Starker Fokus auf KMP bei der Google I/O 24  Dokumentation  Libraries  Und mehr und mehr der eigenen Apps nutzen es

Slide 82

Slide 82 text

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

Slide 83

Slide 83 text

Scaling is hard „Piloting Kotlin Multiplatform is Easy. Scaling is Hard.“ https://touchlab.co/kmp-teams-piloting-vs-scaling

Slide 84

Slide 84 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://speakerdeck.com/writtmeyer/ https://speakerdeck.com/writtmeyer/ https://wolfram-rittmeyer.de/ https://wolfram-rittmeyer.de/ Thanks Picture by Wil Stewart Picture by Wil Stewart

Slide 85

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