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 Slide

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

    View Slide

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

    View Slide

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

    View Slide

  5. Fact:
    Kotlin is a Programming language.

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View 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 Slide

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

    View Slide

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

    View 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 Slide

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

    View Slide

  15. Questions so far?

    View Slide