Compile executables Kotlin Multiplatform

In this article we will find out answers to these questions:

  • kotlin multiplatform compile binaries
  • kotlin multiplatform compile artifacts
  • kotlin multiplatform compile executables
  • kotlin multiplatform fat jar desktop
  • kotlin multiplatform uber jar desktop
  • kotlin multiplatform generate apk
  • kotlin multiplatform build apk

Kotlin Multiplatform project may have these parts:

  • Shared code
  • Android target
  • IOS target
  • Desktop target
  • Server

Important note, that we should execute any Gradle tasks using Run Configurations in Android Studio. Edit Configurations -> Add new -> Gradle -> Paste Gradle task to “Tasks and arguments” field. You may face errors when trying to execute them using ./gradlew directly.


1. Android: generate APK

  • assembleDebug Gradle command. APK will be located at
    <project>/composeApp/build/outputs/apk/release/composeApp-release-unsigned.apk.
  • assembleRelease Gradle command. APK will be located at
    <project>/composeApp/build/outputs/apk/debug/composeApp-debug-unsigned.apk.

If you’re facing with “app not installed as package appears to be invalid” error, most likely you’re trying to install release version; try with debug one. Also, check that minimum Android version matches.


2. Desktop: generate .jar

Open build.gradle.kts, and change this:

kotlin {
  sourceSets {
    desktopMain.dependencies {
      implementation(compose.desktop.currentOs)
    }
  }
}

To this:

kotlin {
  sourceSets {
    desktopMain.dependencies {
      implementation(compose.desktop.macos_arm64)
      implementation(compose.desktop.windows_x64)
      implementation(compose.desktop.linux_x64)
      // Add more if needed
    }
  }
}

And run Gradle task: composeApp:packageUberJarForCurrentOS. Artifact will be located at <project>/composeApp/build/compose/jars/org.mipoder.chat-<current-os-architecture>-1.0.0.jar.

Don’t look at the name of the task and at the name of the artifact. It should work for all specified platforms (in our case – MacOC arm64, Windows x64 and Linux x64).

Don’t forget to install JVM on the target machine (as per August 30, 2024 it should be Java 17). You will be able to open the app using double-click.


3. Server: Generate .jar

Run Gradle task: server:shadowJar. Artifact will be located at <project>/server/build/libs/server-all.jar.


4. MacOS: Generate .app & .dmg

Run Gradle task: composeApp:packageDmg.

  • .app will be located at: <project>/composeApp/build/compose/binaries/main/app/you.app.name.app.
  • .dmg will be located at: <project>/composeApp/build/compose/binaries/main/dmg/you.app.name-1.0.0.dmg.

These are crucial artifact needed to development. This article will be updated with instructions to generate other artifacts.


Telegram channel

If you still have any questions, feel free to ask me in the comments under this article or write me at promark33@gmail.com.

If I saved your day, you can support me 🤝