Last week I showed you how to create a Kotlin Multiplatform project, and run it in a browser as JavaScript. This week, I wanted to show you how to export that exact same code as an XCode Framework that can be used within your iOS application.
March 2021
Intro to Kotlin Multiplatform JavaScript
One of the compilation targets of Kotlin Multiplatform is JavaScript. It’s pretty awesome that I can take the same Kotlin code and tools I write Android with, and write code that runs in a browser (or in Node.js).
Here is the video I’ve created to walk you through the creation of a Kotlin Multiplatform Project using the templates in Intellij IDEA, and what you can do to get your Kotlin running as JavaScript in the Browser!
Here are the code snippets mentioned in the video:
./gradlew build
js(LEGACY) {
browser {
webpackTask {
output.libraryTarget = "this" // Will add to window
}
binaries.executable()
}
}
fun printHi() {
println("Hello World Sam!")
}
fun main(args: Array) {
printHi()
}
helloworldsam.printHi()