Compiling to Other Targets

We'll cover the following

Compilation formats for Kotlin

In addition to all the capabilities that Kotlin offers, it’s one of the few languages that can be compiled to different targets.

  • On Android devices: Kotlin is considered a first-class language for Android development. We’ll explore using Kotlin to create Android applications in Chapter 21, Writing Android Applications with Kotlin.

  • To JavaScript: transpilation is compiling from the source code of one language to the source code of another language. You can see how to transpile Kotlin to JavaScript in Appendix 1, Transpiling to JavaScript.

  • To native targets: when compiling down to a virtual machine isn’t an option, Kotlin/Native can be used to compile your source code to different native targets like iOS, Linux, MacOS, Windows, and others, and can be executed without a virtual machine. See Appendix 2, Kotlin/Native, for an introduction to using Kotlin/Native.

  • To WebAssembly to run in browsers: using Kotlin/Native, you may also compile Kotlin source code to WebAssembly or Wasm, format for virtual machines that run within modern browsers. In Appendix 3, Kotlin to WebAssembly, we’ll explore this capability to create Kotlin code that runs within browsers.

Kotlin also provides different options to run the code as you’ll see in the next lesson.

Get hands-on with 1200+ tech skills courses.