$30 off During Our Annual Pro Sale. View Details »

Kotlin/Native for Multiplatform development

Kotlin/Native for Multiplatform development

Kotlin/Native for Multiplatform development presentation at GDG Kyoto Meetup

Enrique López Mañas

February 10, 2019

More Decks by Enrique López Mañas

Other Decks in Programming


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

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

    KotlinWeekly publisher • @eenriquelopez
  3. Motivation < Costs Sharing code within the company Feature teams

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

  5. Kotlin Modern language

  6. Kotlin

  7. Kotlin Interop

  8. Kotlin Community support

  9. Kotlin Top-notch tooling

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

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

  12. Kotlin/Anywhere Android Browser Server

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

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

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

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

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

  23. Community projects - Sqldelight - Knarch.db - Multiplatform settings -

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

  25. expect/actual

  26. expect/actual

  27. expect/actual JVM

  28. expect/actual JS

  29. Considerations in state An object belongs to one thread

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

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

    is not frozen
  32. Considerations in state No threading primitives: synchronized, volatile Use atomic-fu

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

  34. Get started git clone https://github.com/JetBrains/kotlin-native ./gradlew dependencies:update ./gradlew bundle kotlinc

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

    more performant Kotlin - better ecosystem
  37. Recommendations - Use it with caution - Shared components -

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