JVM Targets
Skotch can produce JVM class files, packaged JARs, DEX bytecode, and unsigned APKs. This guide covers project-level builds for each.
JVM: producing a JAR
Section titled “JVM: producing a JAR”Project structure
Section titled “Project structure”myapp/ build.gradle.kts src/main/kotlin/ Main.kt Utils.ktbuild.gradle.kts
Section titled “build.gradle.kts”plugins { kotlin("jvm") application}
group = "com.example"version = "1.0.0"
application { mainClass.set("MainKt")}Build and run
Section titled “Build and run”cd myappskotch buildjava -jar build/example.jarThe JAR includes a META-INF/MANIFEST.MF with the Main-Class header,
so java -jar works directly.
Multi-module JVM projects
Section titled “Multi-module JVM projects”For projects with library modules:
myapp/ settings.gradle.kts app/ build.gradle.kts src/main/kotlin/Main.kt lib/ build.gradle.kts src/main/kotlin/Helper.ktsettings.gradle.kts:
rootProject.name = "myapp"include(":app", ":lib")app/build.gradle.kts:
plugins { kotlin("jvm") application}
dependencies { implementation(project(":lib"))}
application { mainClass.set("MainKt")}Skotch compiles :lib first, then :app, and merges all class files
into the final JAR.
skotch build -C myappAndroid: producing an APK
Section titled “Android: producing an APK”Project structure
Section titled “Project structure”myapp/ build.gradle.kts src/main/kotlin/ MainActivity.ktbuild.gradle.kts
Section titled “build.gradle.kts”plugins { id("com.android.application") kotlin("android")}
android { namespace = "com.example.myapp" compileSdk = 34
defaultConfig { applicationId = "com.example.myapp" minSdk = 24 targetSdk = 34 versionCode = 1 versionName = "1.0" }}skotch buildThe APK contains:
AndroidManifest.xml— binary AXML generated from the build configclasses.dex— DEX bytecode compiled from your Kotlin sourcesresources.arsc— included if present (optional)
Overriding the target
Section titled “Overriding the target”If your build.gradle.kts uses JVM plugins but you want to produce an
APK:
skotch build --target androidSingle-file compilation
Section titled “Single-file compilation”For quick experiments, skotch emit compiles one file at a time without
needing a project structure:
# JVM class fileskotch emit --target jvm hello.kt -o HelloKt.classjava -cp . HelloKt
# DEX fileskotch emit --target dex hello.kt -o classes.dex
# Native binary (requires clang)skotch emit --target native hello.kt -o hello./hello
# LLVM IR (text)skotch emit --target llvm hello.kt -o hello.ll
# Kotlin library archiveskotch emit --target klib hello.kt -o hello.klibAPK signing
Section titled “APK signing”Skotch supports APK Signature Scheme v2 signing with PEM key files:
android { signingConfigs { debug { storeFile = "keys/debug.pem" storePassword = "" keyAlias = "debug" keyPassword = "" } }}