Kotlin/Native for Multiplatform development

Kotlin/Native for Multiplatform development

Slides of my talk at the AndroidTO. Toronto, 6th November 2018.

7d67eb78fab223823acad6714cd2d3ca?s=128

Enrique López Mañas

November 07, 2018
Tweet

Transcript

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

  2. Ego Slide • Freelance Dev • Google Developer Expert •

    @eenriquelopez
  3. Multiplatform development < Costs Sharing code within the company Feature

    teams > Quality
  4. Multiplatform development Platform Proprietary Hybrid HTML & JavaScript Frameworks Cross-platform

    Native
  5. Kotlin Modern language

  6. Kotlin Interop

  7. Kotlin Community support

  8. Kotlin Top-notch tooling

  9. Kotlin Sharing is optional! No life or death commitment

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

    v0.9.3
  11. Kotlin/Anywhere Android Browser Server

  12. Kotlin/Native Common JVM Native iOS framework Your iOS dev Your

    Android Dev JS
  13. Kotlin/Native Sharing architecture (not UI) Shared UI is a mess

  14. 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)
  15. Kotlin/Native Kotlin Compiler LLVM Kotlin Source Code (.kt) Platform Binary

    IR
  16. The compiler -Shares Front-end with Kotlin/JVM and Kotlin/JS - Written

    in Java and Kotlin - Produces bitcode via LLVM API
  17. 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
  18. 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
  19. 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
  20. 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
  21. Existing native libraries - Ktor - Kotlinx.Coroutines - Kotlinx.io -

    Atomic-fu
  22. Community projects - Sqldelight - Knarch.db - Multiplatform settings -

    Stately - OKIO2 (under development)
  23. expect/actual

  24. expect/actual

  25. expect/actual

  26. expect/actual JVM

  27. expect/actual JS

  28. Considerations in state An object belongs to one thread

  29. Considerations in state Frozen objects can be shared by threads

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

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

  32. Concurrency - frozen objects Everything you have written until now

    is not frozen
  33. Get started git clone https://github.com/JetBrains/kotlin-native ./gradlew dependencies:update ./gradlew bundle kotlinc

    hello.kt -o hello -opt
  34. 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 ”
  35. Flutter vs Kotlin/Native? Flutter - custom UI Widgets Dart -

    better Threading support Kotlin - more performant Kotlin - better ecosystem
  36. Recommendations - Use it with caution - Shared components -

    Keep versioning in mind - Do not compromise 100% of a project
  37. 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)
  38. None