Slide 1

Slide 1 text

22 Mai 2020 | Google Technologies Week Guinea 2020 Développement Android et iOS avec Kotlin Multiplatform Charles “Chuck” Greb Développeur Mobile Co-Lead GDG Ratoma @ecgreb

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Kotlin / Java

Slide 7

Slide 7 text

Presentation Model Storage Network View Kotlin / Java

Slide 8

Slide 8 text

Presentation Model Storage Network View Kotlin / Java

Slide 9

Slide 9 text

Presentation Model Storage Network View Kotlin / Java

Slide 10

Slide 10 text

Presentation Model Storage Network View Kotlin / Java Swift / Obj-C

Slide 11

Slide 11 text

Presentation Model Storage Network View Kotlin / Java Swift / Obj-C JS

Slide 12

Slide 12 text

Presentation Model Storage Network View Presentation Presentation Model Model Storage Storage Network Network View View Kotlin / Java Swift / Obj-C JS

Slide 13

Slide 13 text

Presentation Model Storage Network View View View Kotlin / Java Swift / Obj-C JS

Slide 14

Slide 14 text

Multiplatform Presentation Model Storage Network View View View Kotlin / Java Swift / Obj-C JS

Slide 15

Slide 15 text

Multiplatform Presentation Model Storage Network Activity HTML Document UIViewController Kotlin / Java Swift / Obj-C JS

Slide 16

Slide 16 text

Common

Slide 17

Slide 17 text

JVM Native JS Common

Slide 18

Slide 18 text

JVM Native JS Common Android Java 6 Java 8

Slide 19

Slide 19 text

JVM Native JS Common Android Java 6 Java 8 Browser Node

Slide 20

Slide 20 text

JVM Native JS Common Android Java 6 Java 8 Browser Node iOS Mac Windows Linux WebAssembly …

Slide 21

Slide 21 text

JVM Native JS Common Android Java 6 Java 8 Browser Node iOS Mac Windows Linux WebAssembly …

Slide 22

Slide 22 text

Pourquoi?

Slide 23

Slide 23 text

Avantages et inconvénients Pros and cons Cross-Platform Frameworks Kotlin Multiplatform Pros Single language (Dart, JS, C#) Rapid development Easy to learn Native languages (Kotlin / Swift) Native UI Interoperability Cons Framework UI only Access to system / OS Performance Multiple languages Project setup Learning curve

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

juillet
 2011 Jetbrains
 announces
 project
 Kotlin

Slide 26

Slide 26 text

juillet
 2011 Jetbrains
 announces
 project
 Kotlin janvier
 2015 Using project
 Kotlin for
 Android
 published

Slide 27

Slide 27 text

juillet
 2011 Jetbrains
 announces
 project
 Kotlin mai
 2017 Google
 announces
 official support
 for Kotlin janvier
 2015 Using project
 Kotlin for
 Android
 published

Slide 28

Slide 28 text

juillet
 2011 Jetbrains
 announces
 project
 Kotlin mai
 2017 Google
 announces
 official support
 for Kotlin janvier
 2015 Using project
 Kotlin for
 Android
 published octobre
 2018 Kotlin 1.3
 release with
 experimental
 multiplatform
 suppot

Slide 29

Slide 29 text

juillet
 2011 Jetbrains
 announces
 project
 Kotlin mai
 2017 Google
 announces
 official support
 for Kotlin janvier
 2015 Using project
 Kotlin for
 Android
 published octobre
 2018 Kotlin 1.3
 release with
 experimental
 multiplatform
 suppot mars
 2020 Kotlin1.3.70
 release

Slide 30

Slide 30 text

juillet
 2011 Jetbrains
 announces
 project
 Kotlin mai
 2017 Google
 announces
 official support
 for Kotlin janvier
 2015 Using project
 Kotlin for
 Android
 published octobre
 2018 Kotlin 1.3
 release with
 experimental
 multiplatform
 suppot mars
 2020 Kotlin1.3.70
 release printemps
 2020 Kotlin1.4
 release

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

Kotlin Multiplatform tl;dr • Build configuration • Code sharing • expect and actual • Using typealias • Interfaces • Multiplatform libraries • Multiplatform IDEs

Slide 33

Slide 33 text

Build configuration

Slide 34

Slide 34 text

• Apply plugins • Build targets and source sets • Android dependencies • iOS dependencies Build configuration plugins { kotlin("multiplatform") id("org.jetbrains.kotlin.native.cocoapods")
 id(“com.android.library") } shared/build.gradle.kts

Slide 35

Slide 35 text

• Apply plugins • Build targets and source sets • Android dependencies • iOS dependencies Build configuration kotlin { android() iosX64("ios") sourceSets["commonMain"].dependencies { // ... } sourceSets["androidMain"].dependencies { // ... } sourceSets["iosMain"].dependencies { // ... } cocoapodsext { framework { isStatic = false } } } shared/build.gradle.kts

Slide 36

Slide 36 text

• Apply plugins • Build targets and source sets • Android dependencies • iOS dependencies Build configuration dependencies { implementation(kotlin("stdlib-jdk7", "1.3.72")) implementation(project(":shared")) ... } app/build.gradle.kts

Slide 37

Slide 37 text

• Apply plugins • Build targets and source sets • Android dependencies • iOS dependencies Build configuration use_frameworks! platform :ios, '9.0' install! 'cocoapods', :deterministic_uuids => false target ‘my-ios-app‘ do pod 'shared', :path => '../shared/' end ios/Podfile

Slide 38

Slide 38 text

Code sharing

Slide 39

Slide 39 text

• expect and actual • Using typealias • Interfaces Code sharing expect fun currentTimeMillis(): Long src/commonMain/kotlin/Platform.kt actual fun currentTimeMillis(): Long = System.currentTimeMillis() src/androidMain/kotlin/PlatformAndroid.kt actual fun currentTimeMillis(): Long = (NSDate().timeIntervalSince1970 * 1000).toLong() src/iosMain/kotlin/PlatformiOS.kt

Slide 40

Slide 40 text

• expect and actual • Using typealias • Interfaces Code sharing expect class Date(year: Int, month: Int, day: Int) src/commonMain/kotlin/Date.kt actual typealias Date = java.util.GregorianCalendar src/androidMain/kotlin/Date.kt src/iosMain/kotlin/Date.kt actual class Date { actual constructor(year: Int, month: Int, day: Int) { val calendar = NSCalendar.currentCalendar val components = NSDateComponents() components.setDay(day.toLong()) components.setMonth(month.toLong()) components.setYear(year.toLong()) return calendar.dateFromComponents(comps)!! } }

Slide 41

Slide 41 text

• expect and actual • Using typealias • Interfaces Code sharing interface ApplicationStorage { fun putBoolean(key: String, value: Boolean) } src/commonMain/kotlin/ApplicationStorage.kt internal class AndroidStorage(context: Context) : ApplicationStorage { private val prefs = PreferenceManager .getDefaultSharedPreferences(context) override fun putBoolean(key: String, value: Boolean) { prefs.edit().putBoolean(key, value).apply() } } src/androidMain/kotlin/AndroidStorage.kt internal class IosStorage : ApplicationStorage { private val delegate: NSUserDefaults = NSUserDefaults.standardUserDefaults() override fun putBoolean(key: String, value: Boolean) { delegate.setBool(value, key) } } src/iosMain/kotlin/iOSStorage.kt

Slide 42

Slide 42 text

Multiplatform libraries kotlinx.coroutines Asynchronous or non-blocking programming https://github.com/Kotlin/kotlinx.coroutines Koin Multiplatform dependency injection https://insert-koin.io/ Ktor HTTP utility for connected apps https://ktor.io SQLDelight Typesafe DB management https://cashapp.github.io/sqldelight/ Multiplatform Settings Simple key-value data storage https://github.com/russhwolf/multiplatform-settings Stately Concurrency and state management https://github.com/touchlab/Stately Kermit Composable logging utility https://github.com/touchlab/Kermit Oolong Model-View-Update (MVU) architecture https://oolong-kt.org/ New in Koin 3.0 !

Slide 43

Slide 43 text

Multiplatform IDEs

Slide 44

Slide 44 text

Multiplatform IDEs

Slide 45

Slide 45 text

KaMP Kit https://github.com/touchlab/KaMPKit/

Slide 46

Slide 46 text

La Demo

Slide 47

Slide 47 text

22 Mai 2020 | Google Technologies Week Guinea 2020 fin. Charles “Chuck” Greb Développeur Mobile Co-Lead GDG Ratoma @ecgreb