Slide 1

Slide 1 text

Kotlin Beyond Android Guillermo Orellana @wiyarmir November 2019 Droidcon San Francisco

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

We are in the US! And we are hiring in Los Angeles! Backend, iOS, Android

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Ctrl+Shift+Alt+K ⌘+⇧+⌥+K

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

Backend

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

fun main(args: Array) { embeddedServer(Netty, 8080) { routing { get("/") { call.respondText("Hello World") } } }.start() } http://ktor.io/

Slide 14

Slide 14 text

API Tests #

Slide 15

Slide 15 text

@Test fun `when userId and password provided then user is created`() = testApp(mockStorage) { handleRequest(HttpMethod.Post, endpoint) { addHeader( HttpHeaders.ContentType, ContentType.Application.FormUrlEncoded.toString() ) setBody( listOf( "userId" to testId, "password" to testPassword ).formUrlEncode() ) }.apply { assertThat(response.status(), equalTo(HttpStatusCode.Created)) }

Slide 16

Slide 16 text

Deploying

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

$ git push heroku master

Slide 19

Slide 19 text

Counting objects: 155, done. Delta compression using up to 36 threads. Compressing objects: 100% (50/50), done. Writing objects: 100% (89/89), 17.45 KiB | 0 bytes/s, done. Total 89 (delta 33), reused 75 (delta 19) remote: -----> Cleaning up!!... remote: -----> Building keynotedex from herokuish!!... remote: -----> Adding BUILD_ENV to build environment!!... remote: -----> Gradle app detected remote: -----> Installing JDK 1.8!!... done remote: -----> Building Gradle app!!... remote: -----> executing ./gradlew stage remote: To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https:!//docs.gradle.org/4.10.2/userguide/gradle_daemon.html. remote: Daemon will be stopped at the end of the build stopping after processing remote: > Task :buildSrc:discoverMainScriptsExtensions remote: > Task :buildSrc:compileKotlin remote: > Task :buildSrc:compileJava NO-SOURCE remote: > Task :buildSrc:compileGroovy NO-SOURCE remote: > Task :buildSrc:processResources NO-SOURCE remote: > Task :buildSrc:classes UP-TO-DATE remote: > Task :buildSrc:inspectClassesForKotlinIC remote: > Task :buildSrc:jar remote: > Task :buildSrc:assemble remote: > Task :buildSrc:discoverTestScriptsExtensions remote: > Task :buildSrc:compileTestKotlin NO-SOURCE remote: > Task :buildSrc:compileTestJava NO-SOURCE remote: > Task :buildSrc:compileTestGroovy NO-SOURCE remote: > Task :buildSrc:processTestResources NO-SOURCE remote: > Task :buildSrc:testClasses UP-TO-DATE remote: > Task :buildSrc:test NO-SOURCE remote: > Task :buildSrc:check UP-TO-DATE remote: > Task :buildSrc:build remote: > Task :backend:clean UP-TO-DATE remote: > Task :backend:discoverMainScriptsExtensions remote: > Task :common:compileJava NO-SOURCE remote: > Task :common:compileKotlinCommon remote: > Task :common:processResources NO-SOURCE remote: > Task :common:classes remote: > Task :common:inspectClassesForKotlinIC remote: > Task :common:jar remote: > Task :common-jvm:discoverMainScriptsExtensions remote: > Task :common-jvm:compileKotlin

Slide 20

Slide 20 text

remote: > Task :web:runDceKotlinJs remote: > Task :web:compileJava NO-SOURCE remote: > Task :web:classes remote: > Task :web:compileTestKotlin2Js NO-SOURCE remote: > Task :web:runDceTestKotlinJs NO-SOURCE remote: > Task :web:webpack-config remote: > Task :web:webpack-helper SKIPPED remote: > Task :web:webpack-bundle remote: > Task :web:bundle remote: > Task :web:inspectClassesForKotlinIC remote: > Task :web:jar remote: > Task :web:assemble remote: > Task :web:karma-config SKIPPED remote: > Task :web:karma-run-single SKIPPED remote: > Task :web:compileTestJava NO-SOURCE remote: > Task :web:testClasses UP-TO-DATE remote: > Task :web:test NO-SOURCE remote: > Task :web:check UP-TO-DATE remote: > Task :web:build remote: > Task :backend:copyWebBundle remote: > Task :backend:processReleaseResources remote: > Task :backend:releaseClasses remote: > Task :backend:releaseJar remote: > Task :backend:release remote: > Task :stage remote: remote: Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0. remote: Use '!--warning-mode all' to show the individual deprecation warnings. remote: See https:!//docs.gradle.org/4.10.2/userguide/command_line_interface.html#sec:command_line_warnings remote: remote: BUILD SUCCESSFUL in 9m 8s remote: 32 actionable tasks: 31 executed, 1 up-to-date remote: w: Detected multiple Kotlin daemon sessions at build/kotlin/sessions remote: -----> Discovering process types remote: Procfile declares types !-> web remote: -----> Releasing keynotedex (dokku/keynotedex:latest)!!... remote: -----> Deploying keynotedex (dokku/keynotedex:latest)!!... remote: -----> Attempting to run scripts.dokku.predeploy from app.json (if defined) remote: -----> App Procfile file found (/home/dokku/keynotedex/DOKKU_PROCFILE) remote: -----> DOKKU_SCALE file found (/home/dokku/keynotedex/DOKKU_SCALE) remote: =====> web=1 remote: -----> Attempting pre-!flight checks remote: -----> Attempt 1/5 Waiting for 5 seconds !!...

Slide 21

Slide 21 text

$ git push origin master $ git push heroku master

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

$ git push origin master

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

Web

Slide 28

Slide 28 text

override fun HTML.apply() { head { meta { charset = "utf-8" } meta { name = "viewport" content = "width=device-width, initial-scale=1.0" } title { insert(caption) } insert(head) } body { div { id = "content" }

Slide 29

Slide 29 text

override fun HTML.apply() { head { meta { charset = "utf-8" } meta { name = "viewport" content = "width=device-width, initial-scale=1.0, shrink-to-fit=no" } title { +"Keynotedex" } insert(head) link( rel = LinkRel.stylesheet, type = LinkType.textCss, href = "https:!//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" ) { attributes["integrity"] = "sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" attributes["crossorigin"] = "anonymous" } } body { div { id = "content" } script(src = "https:!//code.jquery.com/jquery-3.2.1.slim.min.js") { attributes["integrity"] = "sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" attributes["crossorigin"] = "anonymous" } script(src = "https:!//cdnjs.cloud!flare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js") { attributes["integrity"] = "sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" attributes["crossorigin"] = "anonymous" } script(src = "https:!//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js") { attributes["integrity"] = "sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" attributes["crossorigin"] = "anonymous" } script { insert(bundle) } }

Slide 30

Slide 30 text

Kotlin JVM kotlinc

Slide 31

Slide 31 text

https://en.wikipedia.org/wiki/React_(JavaScript_library)

Slide 32

Slide 32 text

KotlinJS kotlinc-js

Slide 33

Slide 33 text

window.onload = { document.getElementById("content") .innerHTML = "Hola" }

Slide 34

Slide 34 text

dynamic

Slide 35

Slide 35 text

val a: dynamic = 3 a.`types?` .I.`haven't`.heard .that.name.`in`.years = ")"

Slide 36

Slide 36 text

https://en.wikipedia.org/wiki/React_(JavaScript_library) +

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

Kotlin Native kotlinc-native

Slide 40

Slide 40 text

No content

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

Kotlin Multiplatform

Slide 45

Slide 45 text

Multiplatform Modules

Slide 46

Slide 46 text

MyModule

Slide 47

Slide 47 text

jvmMain androidMain iosMain jsMain commonMain MyModule

Slide 48

Slide 48 text

jvmMain androidMain iosMain jsMain commonMain jvmTest androidTest iosTest jsTest commonTest MyModule

Slide 49

Slide 49 text

jvmMain androidMain iosMain jsMain commonMain MyModule

Slide 50

Slide 50 text

jvmMain androidMain iosMain jsMain commonMain

Slide 51

Slide 51 text

expect / actual

Slide 52

Slide 52 text

jvmMain androidMain iosMain jsMain commonMain MyModule

Slide 53

Slide 53 text

Multiplatform libraries

Slide 54

Slide 54 text

@Serializable data class SubmissionResponse( val submission: Submission )

Slide 55

Slide 55 text

httpClient.submitForm( path = Paths.signIn, formParameters = parametersOf( "userId" to listOf(userId), "password" to listOf(password) ) )

Slide 56

Slide 56 text

launch { getUserProfile.execute("user1") .fold( { state = Error(it) }, { state = Content(it) } ) }

Slide 57

Slide 57 text

Code sharing

Slide 58

Slide 58 text

Repository Domain Logic Presentation View Binding UI Network

Slide 59

Slide 59 text

Repository Domain Logic Presentation View Binding UI Network

Slide 60

Slide 60 text

Repository Domain Logic Presentation View Binding UI Network

Slide 61

Slide 61 text

The present

Slide 62

Slide 62 text

$ curl \ https:!//keynotedex.wiyarmir.es/api/v1/conferences/ \ -H 'accept: application/json'

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

The future

Slide 67

Slide 67 text

Kotlin 1.3.60 ● New Kotlin Native targets ● Symbolication of iOS crashes ● Performance ● New JS plugin improvements ● Multithreaded native coroutines preview

Slide 68

Slide 68 text

Multiplatform architecture ● Don't just share code, share architectural language ● Kotlin Multiplatform an implementation detail

Slide 69

Slide 69 text

Wrapping up

Slide 70

Slide 70 text

Is the tech ready?

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

Judge by yourself

Slide 73

Slide 73 text

https://keynotedex.wiyarmir.es/

Slide 74

Slide 74 text

wiyarmir/keynotedex

Slide 75

Slide 75 text

wiyarmir/kotlin-multiplatform-template

Slide 76

Slide 76 text

Slides: https://speakerdeck.com/wiyarmir/kotlin-beyond-android-2019 Code: github.com/wiyarmir/keynotedex Templates: github.com/wiyarmir/kotlin-multiplatform-template Contact: twitter.com/@wiyarmir