How can the size of a compose desktop app be reduc...
# compose-desktop
p
How can the size of a compose desktop app be reduced? I tried with "suggestRuntimeModules" result adding "modules("java.instrument", "jdk.unsupported")" but the resulting output size for a Hello World app is still the same than before adding that line, 110 MB. Also, I'm searching if it is possible to combine the resulting folders called "app" and "runtime" inside the .exe application, for making it more comfortably portable. Is it possible?
a
Are you building the “release” version?
For my app, the msi file is 68MB. macOS x86 is 70MB, macOS aarch64 is 80MB, and that’s the debug builds.
Extracted, on disk, it’s going to be larger, obviously.
p
@Alexander Maryanovsky ouch, not, I was creating normal distributable, not release version. BTW I now tried it and got this exception: "Caused by: java.io.IOException: Can't process class [ComposableSingletons$MainKt$lambda-1$1.class] (Unsupported version number [65.0] (maximum 62.65535, Java 18))".
OK I switched to JDK 17, and now it worked, but now the resulting app it's 100 MB (65 for the runtime subfolder and 35 for the app subfolder). It is a lot for a hello world app.
can it be reduced? also.. can those subfolders be included inside the .exe file? to make easily portable the executable file?
a
You need to configure ProGuard correctly in order to build “release” distributables, or it will remove files/code it thinks isn’t used.
Unfortunately no, the JRE can’t be run from inside the executable.
p
do you think proguard is the cause of the error "Unsupported version number [65.0] (maximum 62.65535, Java 18))" ?
m
@Pablo looks like you might be using java 21?
There's no way to make a single EXE with the default Compose toolchain, but you probably don't want that in the way you think. If you use Conveyor (see the CfD docs for a brief discussion) then it'll generate a small 500kb EXE that either runs your app, or downloads+installs it "silently" (progress bar but no user interaction) and then runs it. It'll also keep your app up to date, which is always the next question.
This gives you a user experience very close to the single small EXE case, but with the advantage that you can actually change your app after distributing it.
If the user re-runs the "installer" then the app starts immediately, so from their perspective it looks like it was actually a self-contained app.
p
thanks I'll consider it
yes I was using java 21, now it worked with 17
👍 1
but Alexander told that it is caused by a wrong proguard config? @Alexander Maryanovsky
a
Unsupported class file version is caused by compiling for a newer version of Java than the one it’s being run with.
p
ok
is it possible to reduce more the size? 100 MB is still a lot for a hello world
this is a very powerful tool for creating desktop apps, It haves a great potential
a
If you’re talking about extracted size, then not currently.
m
You could take a look at GraalVM native image, there have been some advanced users who used it to create a single EXE but it doesn't necessarily make your program smaller, just start faster and use less RAM. And it's not supported and can be quite challenging to use with CfD. Unfortunately the native components are quite large all by themselves, like skiko and the unicode data. There's potential to shrink it somewhat but not by huge amounts.
p
thank you guys
m
I'm curious what's your use case where the size is so important?
👍 1
m
You can configure ProGuard like this:
Copy code
compose.desktop {
    application {
    	...
        buildTypes.release {
            proguard {
                version.set("7.4.0")
                isEnabled.set(true)
                optimize.set(false)
                obfuscate.set(false)
                configurationFiles.from(project.file("<http://compose-desktop.pro|compose-desktop.pro>"))
            }
        }
    }
}
When you set the version to the latest one you can also use Java 21. The default one still seems to be limited to Java 18 (see your error message above).
Trying to use GraalVM will not help you: • It won’t make your executable smaller. • It currently does not work with compose desktop (at least on some platforms where proper AWT support is missing.)
p
thank you
I'm doing simply a hello world, and before starting bigger projects I have in mind, I prefeer to have a little more knowledge, so because that I asked about how to reduce size if the app is small.
I'm android developer, but I always loved more to develop for desktop, and this is my opportunity to learn and start releasing projects on desktop at the same time I continue growing in android.
I hope Compose for Desktop will not stop growing and will be even better soon. Also Compose multiplatform native is my future objective but it is too much soon for that
a
We’re working on it 😉
☝️ 1
p
Compose for desktop is a very nice option
thank you for your great work
m
I wouldn’t worry so much about the size of hello-world programs. For real applications this does not really matter and even native real-world applications are often several hundred megabytes large.
p
good point
452 Views