Is there a way to create native-binary from Jetpack Compose Desktop app using GraalVM?

1.6k Views Asked by At

I want to create a small binary out of my Compose desktop app. Following are the options out of the box with Compose:

  1. Create native package with java runtime (great, but the size is very big)
  2. Create an Uber (fat) Jar (but it requires Java 11 to run, since Compose library doesn't support older versions)

I believe it is be possible to convert the Uber Jar to native binary using GraalVM. I also tried running native-image command but it created an exe that in turn runs the Jar, which brings back to the same issue; Java 11 has to be installed on the machine. What am I missing?

1

There are 1 best solutions below

0
On

Compose for desktop uses Swing in the background, so it is not fully compatible yet with GraalVM's native-image tool.

The latest version of GraalVM introduced experimental support for Swing on Linux, but it is still in development. Presumably once Swing support is stable, Compose should work with native-image.

What is happening in your example is that native-image fails to create the native executable, and instead creates a fallback image, which uses a regular JVM runtime.