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

Kotlin Multiplatform

Stefan M.
December 10, 2019

Kotlin Multiplatform

Given at an internal company knowledge sharing meeting.

This presentation is about the "basics" behind Kotlin Multiplatform.

Stefan M.

December 10, 2019
Tweet

More Decks by Stefan M.

Other Decks in Programming

Transcript

  1. Kotlin Multiplatform

    View full-size slide

  2. Kotlin
    Kotlin/JVM
    Kotlin/Native
    Kotlin/JS
    Kotlin Multiplatform
    Easter Egg

    View full-size slide

  3. Kotlin
    Kotlin/JVM
    Kotlin/Native
    Kotlin/JS
    Kotlin Multiplatform
    Easter Egg

    View full-size slide

  4. Warning:
    The next slides are not 100% accurate
    but give you a visualisation about how
    Kotlin Multiplatform works

    View full-size slide

  5. Fact:
    Kotlin is a Programming language.

    View full-size slide

  6. Fact:
    Each language has to converted to something which can be
    understand by "a computer".
    We call these converters compiler.

    View full-size slide

  7. Fact:
    Jetbrains provides different compilers for one language.

    View full-size slide

  8. Fact:
    Jetbrains provides different compilers for one language.
    1. JVM
    2. Native
    3. JS

    View full-size slide

  9. Fact:
    Kotlin can be converted to
    Java Bytecode (via JVM compiler)
    Machine code (via Native compiler)
    JavaScript (via JS compiler)

    View full-size slide

  10. fun main() {
    println("HelloWorld")
    }
    Example
    $ kotlinc HelloWorld.kt -include-runtime -d hello.jar
    $ java -jar hello.jar
    HelloWorld
    $ konanc HelloWorld.kt -o hello
    $ ./hello.kexe
    HelloWorld
    $ kotlinc-js HelloWorld.kt -output hello.js
    $ cat hello.js
    // JS Code nobody wants to see

    View full-size slide

  11. Please note that we talk about pure Kotlin code.
    No dependencies to other worlds (like JVM, C or JS).

    View full-size slide

  12. But - because the compiler knows about other worlds it is
    possible to use the respective dependencies!

    View full-size slide

  13. Example
    expect currentTime: Long
    fun printTime() {
    println("It is $currentTime o'clock")
    }
    common.kt // No dependencies to other worlds
    actual currentTime: Long =
    java.lang.System.currentTimeMillis()
    fun main() = printTime()
    jvm.kt
    actual currentTime: Long =
    platform.posix.time(null)
    fun main() = printTime()
    native.kt
    actual currentTime: Long =
    kotlin.js.Date.now()
    fun main() = printTime()
    js.kt

    View full-size slide

  14. Now we can compile each target (jvm, native, js)
    with the respective compiler

    View full-size slide

  15. Questions so far?

    View full-size slide