Slide 1

Slide 1 text

Kotlin/Native for Multiplatform Development Enrique López Mañas Google Developer Expert

Slide 2

Slide 2 text

Ego Slide • Freelance Dev • Google Developer Expert • @eenriquelopez

Slide 3

Slide 3 text

Multiplatform development < Costs Sharing code within the company Feature teams > Quality

Slide 4

Slide 4 text

Multiplatform development Platform Proprietary Hybrid HTML & JavaScript Frameworks Cross-platform Native

Slide 5

Slide 5 text

Kotlin Modern language

Slide 6

Slide 6 text

Kotlin Interop

Slide 7

Slide 7 text

Kotlin Community support

Slide 8

Slide 8 text

Kotlin Top-notch tooling

Slide 9

Slide 9 text

Kotlin Sharing is optional! No life or death commitment

Slide 10

Slide 10 text

Current situation Q2 Q3 Q4 Q1 Q2 v0.7 v0.8 v0.8.2 v0.9.3

Slide 11

Slide 11 text

Kotlin/Anywhere Android Browser Server

Slide 12

Slide 12 text

Kotlin/Native Common JVM Native iOS framework Your iOS dev Your Android Dev JS

Slide 13

Slide 13 text

Kotlin/Native Sharing architecture (not UI) Shared UI is a mess

Slide 14

Slide 14 text

Kotlin/Native - Uses LLVM (5.0) - Provides runtime guarantees - Exceptions, memory management - Interop with C/Objective-C (Swift) - Platform libraries (POSIX, Apple Frameworks, Win32, DOM, etc)

Slide 15

Slide 15 text

Kotlin/Native Kotlin Compiler LLVM Kotlin Source Code (.kt) Platform Binary IR

Slide 16

Slide 16 text

The compiler -Shares Front-end with Kotlin/JVM and Kotlin/JS - Written in Java and Kotlin - Produces bitcode via LLVM API

Slide 17

Slide 17 text

Memory Management - ARC with Cycle Collector - When working pure Kotlin,don’t worry about memory management - Weak references supported - Memory sharing model - Different threads have disjoint object graphs - Object subgraphs can be transferred between threads - Immutable objects can be shared

Slide 18

Slide 18 text

Interoperatibility - Interoperatibility with C, Objective-C and Swift - Kotlin can call C/Objective-C and vice-versa - Kotlin can extend Objective-C classes and vice-versa - Memory management aware of Objective-C runtime

Slide 19

Slide 19 text

Mapping - Numbers are kept - Strings converted - Kotlin declarations wrapping C entities (functions, struct, unions, etc.) are auto- generated - Objective-C OO concepts (classes, protocols, blocks) are represented as matching Kotlin entities (classes interfaces, lambdas) - For Objective-C, Kotlin code can be compiled to a framework

Slide 20

Slide 20 text

Kotlin Library - Hold collection of code for reusability and sharing - Own format: ‘klib’ extension, which holds metadata and bitcode - Tool for creating and storing libraries in repositories

Slide 21

Slide 21 text

Existing native libraries - Ktor - Kotlinx.Coroutines - Kotlinx.io - Atomic-fu

Slide 22

Slide 22 text

Community projects - Sqldelight - Knarch.db - Multiplatform settings - Stately - OKIO2 (under development)

Slide 23

Slide 23 text

expect/actual

Slide 24

Slide 24 text

expect/actual

Slide 25

Slide 25 text

expect/actual

Slide 26

Slide 26 text

expect/actual JVM

Slide 27

Slide 27 text

expect/actual JS

Slide 28

Slide 28 text

Considerations in state An object belongs to one thread

Slide 29

Slide 29 text

Considerations in state Frozen objects can be shared by threads

Slide 30

Slide 30 text

Considerations in state No threading primitives: synchronized, volatile Use atomic-fu instead

Slide 31

Slide 31 text

Considerations in state Runtime safety: Kotlin/Native can verify safe mutability

Slide 32

Slide 32 text

Concurrency - frozen objects Everything you have written until now is not frozen

Slide 33

Slide 33 text

Get started git clone https://github.com/JetBrains/kotlin-native ./gradlew dependencies:update ./gradlew bundle kotlinc hello.kt -o hello -opt

Slide 34

Slide 34 text

The future Hard to make predictions, easier to bet safe “I don’t know what will happen in 10 years, but there will be people asking in SO about regular expressions, and there will be another JS framework ”

Slide 35

Slide 35 text

Flutter vs Kotlin/Native? Flutter - custom UI Widgets Dart - better Threading support Kotlin - more performant Kotlin - better ecosystem

Slide 36

Slide 36 text

Recommendations - Use it with caution - Shared components - Keep versioning in mind - Do not compromise 100% of a project

Slide 37

Slide 37 text

Further resources Kotlin Slack (kotlinlang.slack.com) Touchlab resources (https://github.com/touchlab) Kotlin Weekly (http://kotlinweekly.net) K/N documentation (https://kotlinlang.org/docs/ reference/native-overview.html)

Slide 38

Slide 38 text

No content