Hello, World!
This guide walks through compiling a single Kotlin file to every supported target format.
Write the source
Section titled “Write the source”Create a file called hello.kt:
fun main() { println("Hello, world!")}Compile to each target
Section titled “Compile to each target”skotch emit --target jvm hello.kt -o HelloKt.classjava -cp . HelloKtHello, world!The output is a standard Java 17 class file. You can inspect it with
javap -c HelloKt.class if you have the JDK installed.
skotch emit --target dex hello.kt -o classes.dexThis produces a Dalvik executable suitable for inclusion in an Android
APK. You can verify it with dexdump -d classes.dex if you have the
Android SDK build-tools.
skotch emit --target klib hello.kt -o hello.klibunzip -l hello.klibA klib is a ZIP archive containing serialized IR and metadata. It serves as the intermediate format for the LLVM and native pipelines.
LLVM IR
Section titled “LLVM IR”skotch emit --target llvm hello.kt -o hello.llcat hello.llProduces about 15 lines of textual LLVM IR. The println call maps to
libc puts.
Native binary
Section titled “Native binary”skotch emit --target native hello.kt -o hello./helloHello, world!A more interesting example
Section titled “A more interesting example”Create math.kt:
fun factorial(n: Int): Int { var result = 1 for (i in 1..n) { result *= i } return result}
fun main() { for (i in 1..10) { println("$i! = ${factorial(i)}") }}skotch emit --target jvm math.kt -o MathKt.classjava -cp . MathKt1! = 12! = 23! = 64! = 245! = 1206! = 7207! = 50408! = 403209! = 36288010! = 3628800This example exercises functions, for loops, mutable variables, compound assignment, and string templates — all features that work across every target.
Project build
Section titled “Project build”For projects with multiple source files, use skotch build instead of
skotch emit. Create a project directory:
myapp/ build.gradle.kts src/main/kotlin/ Main.ktWith a minimal build.gradle.kts:
plugins { kotlin("jvm") application}
group = "com.example"version = "1.0.0"
application { mainClass.set("MainKt")}Then build and run:
cd myappskotch buildjava -jar build/example.jarNext steps
Section titled “Next steps”- CLI Reference — All available subcommands and flags
- Language Overview — Supported Kotlin features
- JVM Targets — JAR packaging and Android APKs