Slide 1

Slide 1 text

A Multiplatform Adventure workshop edition @cafonsomota

Slide 2

Slide 2 text

Android Dev Lead @WITSoftware Founder @GDGCoimbra and co-founder @Kotlin_Knights ✍ Author @rwenderlich and @opinioesonline Podcaster wannabe Loves travel, photography and running @cafonsomota

Slide 3

Slide 3 text

MATERIALS speakerdeck.com/cmota/a-multiplatform-adventure github.com/cmota/kmm-a-multiplatform-adventure cmota.github.io/kmp-codelabs IDE’s required Android Studio Xcode @cafonsomota

Slide 4

Slide 4 text

@cafonsomota install KMM plugin on Android Studio

Slide 5

Slide 5 text

$ git clone https:!//github.com/cmota/kmm-all-together-now.git install KMM plugin on Android Studio github.com/cmota/kmm-all-together-now

Slide 6

Slide 6 text

$ git clone https:!//github.com/cmota/kmm-all-together-now.git AllTogetherNow [kmm-all-together-now/00. Starter Project] install KMM plugin on Android Studio github.com/cmota/kmm-all-together-now open “00. Starter Project”

Slide 7

Slide 7 text

$ git clone https:!//github.com/cmota/kmm-all-together-now.git AllTogetherNow [kmm-all-together-now/00. Starter Project] install KMM plugin on Android Studio github.com/cmota/kmm-all-together-now open “00. Starter Project” wait for gradle to finish

Slide 8

Slide 8 text

xkcd.com/303/

Slide 9

Slide 9 text

> Task :shared:cinteropFirebaseFirestoreIos FAILED 2 actionable tasks: 1 executed, 1 up-to-date xcrun: error: unable to find utility "xcodebuild", not a developer tool or in PATH Exception in thread "main" org.jetbrains.kotlin.konan.MissingXcodeException: An error occurred during an xcrun execution. Make sure that Xcode and its command line tools are properly installed. at org.jetbrains.kotlin.konan.target.CurrentXcode.xcrun(Xcode.kt:77) at org.jetbrains.kotlin.konan.target.CurrentXcode.access$xcrun(Xcode.kt:45) at org.jetbrains.kotlin.konan.target.CurrentXcode$version$2.invoke(Xcode.kt:70) at org.jetbrains.kotlin.konan.target.CurrentXcode$version$2.invoke(Xcode.kt:45) at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74) AllTogetherNow [kmm-all-together-now/00. Starter Project] install KMM plugin on Android Studio github.com/cmota/kmm-all-together-now open “00. Starter Project” wait for gradle to finish ❌ no Xcode installed

Slide 10

Slide 10 text

!/* If you don't have Xcode installed comment this code block!*/ !/* Search for this comment on build.gradle.kts (:shared) and comment all the references to iOS: * - onPhone * - cocoa pods * - iosMain * - iosTest * - packForXcode * - tasks.getByName(“build”) !*/ AllTogetherNow [kmm-all-together-now/00. Starter Project] install KMM plugin on Android Studio github.com/cmota/kmm-all-together-now open “00. Starter Project” wait for gradle to finish comment iOS related blocks on build.gradle.kts (:shared)

Slide 11

Slide 11 text

BUILD SUCCESSFUL in 11s 44 actionable tasks: 44 executed AllTogetherNow [kmm-all-together-now/00. Starter Project] install KMM plugin on Android Studio github.com/cmota/kmm-all-together-now open “00. Starter Project” wait for gradle to finish ✅ Xcode installed

Slide 12

Slide 12 text

iosApp: pod install install KMM plugin on Android Studio github.com/cmota/kmm-all-together-now open “00. Starter Project” wait for gradle to finish go to iosApp folder on Terminal and execute “pod install”

Slide 13

Slide 13 text

install KMM plugin on Android Studio github.com/cmota/kmm-all-together-now open “00. Starter Project” wait for gradle to finish go to iosApp folder on Terminal and execute “pod install” compile and run the app $ git clone https:!//github.com/cmota/kmm-all-together-now.git AllTogetherNow [kmm-all-together-now/00. Starter Project]

Slide 14

Slide 14 text

@cafonsomota and now we wait… (In KMM defense, well we’ve got the FirebaseFirestore lib as a pod)

Slide 15

Slide 15 text

dev-reactions/crash-in-production.gif

Slide 16

Slide 16 text

A Multiplatform Adventure A bit of theory… @cafonsomota

Slide 17

Slide 17 text

@cafonsomota dev-reactions/commitstrip/unrealist-mobile-dev-dream

Slide 18

Slide 18 text

2008 2012 2018 2013 2011 2017 2006 2010 2009 2015 * Kotlin Multiplatform *

Slide 19

Slide 19 text

- Smaller team - Small learning curve for web developers - Typically half of the cost needed on native - Less time (working hours) to built (advantages) Cross-platform to test to fix issues (hopefully not framework specific )

Slide 20

Slide 20 text

- Chained to the framework implementation of UI - new updates from the OS will take time to adopt - Performance is not the same - Some native code might need to be written - OS/ device features are dependent on the fw support - Dart (flutter) is not widely used language (for now) - Committed to one framework/ language (disadvantages) Cross-platform

Slide 21

Slide 21 text

what about Kotlin Multiplatform?

Slide 22

Slide 22 text

shares application logic doesn’t share the application UI kotlin multiplatform

Slide 23

Slide 23 text

- Chained to the framework implementation of UI - new updates from the OS will take time to adopt - Performance is not the same - Some native code might need to be written - OS/ device features are dependent on the fw support - Dart (flutter) is not widely used language (for now) - Committed to one framework/ language (disadvantages) Cross-platform

Slide 24

Slide 24 text

- Chained to the framework implementation of UI - new updates from the OS will take time to adopt - Performance is not the same - Some native code might need to be written - OS/ device features are dependent on the fw support - Dart (flutter) is not widely used language (for now) - Committed to one framework/ language Cross-multiplatform UI is developed natively nope, as fast as an update to the SDK and recompile the apps

Slide 25

Slide 25 text

- Chained to the framework implementation of UI - new updates from the OS will take time to adopt - Performance is not the same - Some native code might need to be written - OS/ device features are dependent on the fw support - Dart (flutter) is not widely used language (for now) - Committed to one framework/ language Cross-multiplatform nope, as fast as an update to the SDK and recompile the apps UI is developed natively always arguable, but you’re leaving UI to native, so…

Slide 26

Slide 26 text

- Chained to the framework implementation of UI - new updates from the OS will take time to adopt - Performance is not the same - Some native code might need to be written - OS/ device features are dependent on the fw support - Dart (flutter) is not widely used language (for now) - Committed to one framework/ language Cross-multiplatform nope, as fast as an update to the SDK and recompile the apps yes, the UI UI is developed natively always arguable, but you’re leaving UI to native, so…

Slide 27

Slide 27 text

- Chained to the framework implementation of UI - new updates from the OS will take time to adopt - Performance is not the same - Some native code might need to be written - OS/ device features are dependent on the fw support - Dart (flutter) is not widely used language (for now) - Committed to one framework/ language Cross-multiplatform nope, as fast as an update to the SDK and recompile the apps yes, the UI UI is developed natively you have direct access to them; although if on shared module it might give you extra effort always arguable, but you’re leaving UI to native, so…

Slide 28

Slide 28 text

- Chained to the framework implementation of UI - new updates from the OS will take time to adopt - Performance is not the same - Some native code might need to be written - OS/ device features are dependent on the fw support - Dart (flutter) is not widely used language (for now) - Committed to one framework/ language Cross-multiplatform nope, as fast as an update to the SDK and recompile the apps yes, the UI UI is developed natively kotlin, is one of the most trending languages nowadays, with strong community support always arguable, but you’re leaving UI to native, so… you have direct access to them; although if on shared module it might give you extra effort

Slide 29

Slide 29 text

(advantages) - Language features - Kotlin first! - Low risk - You decide what’s worth to share across platforms - Interoperability - Consistency across platforms - Strong investment from JetBrains and community support Kotlin Multiplatform server web native android desktop jvmMain jsMain androidMain iosMain macosX64Main linuxX64Main mingwX64Main

Slide 30

Slide 30 text

- It’s in alpha - Although we keep seeing new projects in production - Space was announced during Kotlin Conf 19 (web, desktop and mobile) (apps in production) Kotlin Multiplatform Space Adapted from: KotlinConf 2019: Opening Keynote by Andrey Breslav Full KMP Cash App Shares: business logic Yandex Maps Shares: business logic, wrappers for C++ libraries PlanGrid Planboard Workspace Shares: business logic, sync logic, mgmnt offline data Shares: business logic, networking, offline caching lyrs Shares: business logic

Slide 31

Slide 31 text

- Open source - Concise, safe, interoperable, tool-friendly - Supported/ used by Google for Android Development - It’s more than “just for Android” - Small learning curve involved - Easily to go from JavaScript/ Swift into Kotlin and back Kotlin

Slide 32

Slide 32 text

var variable = 42 variable = 1 let value = 42 var variable = 42 variable = 1 val value = 42 *adapted from http://nilhcem.com/swift-is-like-kotlin/ (variables and constants) Kotlin vs Swift Kotlin Swift

Slide 33

Slide 33 text

fun greet(name: String, day: String): String { return "Hello $name, today is $day." } greet(“World”, “Thursday”) *updated from http://nilhcem.com/swift-is-like-kotlin/ func greet(_ name: String,_ day: String) -> String { return "Hello \(name), today is \(day)." } greet(“World”, “Thursday”) Kotlin Swift (functions) Kotlin vs Swift

Slide 34

Slide 34 text

K otlin multiplatform using kotlin in projects that target more than one platform

Slide 35

Slide 35 text

network network network parser parser parser model model model presentation presentation presentation model parser network view presentation view view view presentation presentation presentation desktop web iOS android

Slide 36

Slide 36 text

business logic business logic business logic model parser network presentation model parser network presentation model parser network presentation model parser network presentation business logic view view view view desktop web iOS android

Slide 37

Slide 37 text

android iOS web desktop model parser network presentation common view view view view java/kotlin objective-c/ swift (kotlin) JS supported in jvm

Slide 38

Slide 38 text

dev-reactions/it-works.gif

Slide 39

Slide 39 text

but how can different platforms expect to communicate?

Slide 40

Slide 40 text

declared at common module expect declared at android module actual declared at iOS module declared at …

Slide 41

Slide 41 text

we want a platform-specific value for the device name

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

dev-reactions/god-mode.gif

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

- User interface - RecyclerView and more (Android) - UITableViewController and more (iOS) - Multiple network request - Parse response objects - Store on local database - Use system preferences - Migrate code to Multiplatform Project structure

Slide 49

Slide 49 text

android iOS Room CoreData Retrofit Alamofire GSON/ Moshi JSONSerialization MVP, MVVM, MVI MVVM, ELM RxJava RxSwift Tests Tests Activity UIViewController RecyclerView UITableView

Slide 50

Slide 50 text

Room CoreData Retrofit Alamofire GSON/ Moshi JSONSerialization MVP, MVVM, MVI MVVM, ELM RxJava RxSwift Tests Tests Activity UIViewController RecyclerView UITableView android iOS

Slide 51

Slide 51 text

Room CoreData Retrofit Alamofire GSON/ Moshi JSONSerialization MVP, MVVM, MVI MVVM, ELM RxJava RxSwift Tests Tests Activity UIViewController RecyclerView UITableView android iOS Activity UIViewController RecyclerView UITableView unnecessary duplication

Slide 52

Slide 52 text

SQLDelight ktor kotlinx.serialization MVP kotlinx.coroutines kotlin.test android iOS Activity UIViewController RecyclerView UITableView

Slide 53

Slide 53 text

multiplatform ktor SQLDelight model kotlinx.serialization SendMessages GetConferences SQLDriver dispatcher view presenter Settings Firebase presenter

Slide 54

Slide 54 text

@cafonsomota cmota.github.io/kmp-codelabs/ cmota.github.io/kmp-codelabs

Slide 55

Slide 55 text

@cafonsomota > Configure project :shared Kotlin Multiplatform Projects are an Alpha feature. cmota.github.io/kmp-codelabs

Slide 56

Slide 56 text

speakerdeck.com/cmota/a-multiplatform-adventure github.com/cmota/kmm-a-multiplatform-adventure cmota.github.io/kmp-codelabs @cafonsomota