Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Kotlin/Native (DevFest Strasbourg 2019)

Kotlin/Native (DevFest Strasbourg 2019)

Kotlin/Native... what's that?
How does it work?
It permits to use Kotlin code in iOS app written in Swift, but how?
Can we use it in production?

Let met explain this project made by JetBrains which has the aim to run Kotlin binaries on many platforms. I will also make a return of experience with the integration of Kotlin code as Xcode framework for an iOS app, with its benefits and limits.

This talk has been made for DevFest Strasbourg 2019.
Slidedeck under CC-BY-SA.

You enjoyed reading these slides? Buy me a beer, thanks<3

Pierre-Yves Lapersonne

October 23, 2019

More Decks by Pierre-Yves Lapersonne

Other Decks in Technology


  1. Release 5 – 24/10/2019 ✿✿✿✿ ʕ •ᴥ•ʔ/ ︻デ═⼀一 This document

    is available under terms of Creative Commons with CC-BY-SA 3.0
  2. Kotlin • Created by JetBrains
 • Mix of object &

    functional paradigms • Static & inferred typing
 • Open source, under Apache 2 license
 • Compilable for Java & JS VM, C, Objective-C • Last version: 1.3.4 6
  3. 7

  4. Kotlin for Android 11 😻 Note: Here is the Kotlin

    code converted from Java code with Android Studio (a bit dirty!!)
  5. 12

  6. Definition « Kotlin/Native is a technology for compiling Kotlin code

    to native binaries, which can run without a virtual machine. It is an LLVM based backend for the Kotlin compiler and native implementation of the Kotlin standard library. » 14 Source: kotlinlang.org
  7. Kotlin/Native • Will not replace legacy frameworks • Allows to

    have bidirectional interop. between Kotlin and target code ! To mutualize/share source code between platforms 
 Code common, respect the platform 15
  8. Targets • A lot of platforms… • … where we

    cannot have or don’t want VM 16
  9. Use case 28 Use case: refactoring with K/N of data

    model in a 100% Swift TV channels app
  10. Source sets 30 Possible to define several source sets, with

    EXPECTed methods and ACTUAL definitions based on targets. Project libs src common android ios expect (class, val…) actual (class, val…) actual (class, val…)
  11. 42

  12. 47

  13. 55 [Swift] No use of generic on this side, only

    the TYPE in the Kotlin condition
  14. 58 [Swift] No use of generic on this side, only

    the TYPE of the 1st condition in Kotlin is used
  15. 64 [Swift] "Exceptions are propagated […] as NSError only if

    method has or inherits @Throws annotation" ( ) Except with kotlin.Error and RuntimeException which are not propagated * *
  16. Things to note • Kotlin project can be a dependance

    or a full program with a main • Platforms libs ensure interoperability • A specific environment may be mandatory to compile for a specific platform 70
  17. 72 KOTLIN code loading HTML page using a POD and

    displaying it inside a UITextView of the target from APPLE UIKit
  18. Limits • Web Assembly / JS • No exceptions management

    • No efficient memory management • No debugging • iOS • Beware with the Objective-C layer • Some Java APIs are not available • java.util.Date, java.math.BigDecimal
 ! Must use platforms libs like POSIX 73
  19. Conclusion • K/N interesting for data model or work logic

    • Good integration in iOS projects • Gradle’s black magic is helpful (but heavy) • Kotlin extensions bring multiplatforms API 74
  20. Ready for production? 75 Not today? It seems IceRock and

    Rekab use Kotlin/Native. « This beta version of Kotlin/Native technology is not yet tuned for benchmarking and competitive analysis of any kind. » GitHub
  21. To go further • Building Multiplatform Projects with Gradle –

    kotlinlang.org • Getting started with Kotlin/Native – sakib.ninja • JetBrains / kotlin-native – GitHub • JetBrains / kotlin-native / samples – GitHub • Kotlin Multiplatform - Medium.com, Mehdi Sohrabi • Kotlin on Android. Now official – blog.jetbrains.com, Maxim Shafirov • Kotlin/Native + CLANG, travel notes – Nikolai Igotti (JetBrains) • Kotlin/Native and Multiplatform – raywenderlich.com • Kotlin/Native as an Apple Framework – kotlinlang.org • Kotlin/Native interoperability – kotlinlang.org • Kotlin/Native interoperability with Swift/Objective-C – kotlin.org • LLVM – Chris Lattner • My first experience with Kotlin Native – Medium.com, Florent Champigny • Plateform-Specific implementations in Kotlin Multiplatform - medium.com, Simone Civetta • Targeting iOS and Android with Koltin Multiplatform – play.kotlinlang.og • The magic of Kotlin/Native (1, 2, 3) – Medium.com, Vivek Singh • What is LLVM? The power behind Swift, Rust, Clang, and more – InfoWorld.com, Serdar Yegulalp • Why we need Kotlin/Native - Medium.com, Jeremy Rempel 78
  22. Credits • Native_overview.png – modified with Gimp • Capture of

    Captain America: Civil War – Marvel Studios ; Marvel Entertainment ; Russo Brothers ; Vita-Ray Productions, LLC • Bugdroid, la mascotte représentant Android – CC-BY-SA 3.0, Google Inc. • Java free icon – Flaticon Basic License, Freepik • Hero.svg – modified with Gim • Logo de iOS – public domain, Apple Inc. • Logo de macOS – public domain, Apple Inc. • Logo de watchOS – public domain, Apple Inc. • Logo de tvOS – public domain, Apple Inc. • Logo de Android – public domain • Logo de Windows – public domain • Logo de Linux – CC0, Larry Ewing, Simon Budig, Garrett LeSage • Logo de Raspberry Pi – Copyright Apache Cordova • Logo de Web Assembly – CC0, Carlos Beraza • Logo de JavaScript – public domain, Chris Williams • Engine free icon – Flaticon Basic License, Flat Icons 79 • Binary code free icon – Flaticon Basic License, Freepik • Logo de IntelliJ IDEA – public domain, JetBrains • Logo de Xcode – Apple • Logo de Swift – public domain, modified with Gimp • Logo of Gradle • Code samples wrapped with Carbon • iPhone mockup made with Smartmockups • Logo of Code d’Armor – Copyright © Code d’Armor • Logo of DevFest du Bout du Monde - Copyright © DevFest du Bout du Monde • Logo of Orange – public domain, Cbuckley • Logo of DevFest 3019 and wallpaper – Copyright © GDG Strasbourg • Memes created with imgflip.com In random order