Hello, does anyone have a working example of build...
# multiplatform
n
Hello, does anyone have a working example of building a shareable
.exe
or similar using the desktop target and Ktor? I want to share to a friend a small application I made using Kotlin Multiplatform, without them installing a JDK. I have a cryptic error after the
.msi
installation and launch of the installed `.exe`: "java/net/http/HttpClient$Version`, followed by a
Failed to launch JVM
(I though I was building native code, not JVM code ???) Ofc the ktor documentation is not helping. The Compose Multiplatform documentation is not really helping either. I tried every command here, at worst it doesn't compile, at best the produced and installed
.msi
can't launch the application. The only working example trying to build a shareable binary I could find was this repo https://github.com/JetBrains/compose-multiplatform/tree/master/examples/imageviewer, but it's not using Ktor and I guess the issue is around Ktor on a release? NB: Launching the debug app from Intellij works fine. I just want to share my application with my non-tech friends.
m
You should try the task runReleaseDistributable to see what's happening. All installers which you create here contain a bundled JRE. They don't create anything native.
👍 2
n
It doesn't compile unfortunately
Untitled
e
java.net.http is a module included in the JRE, either your installer isn't packaging it or your package is missing some declaration to use it
m
You probably have to add a line like this to your "nativeDistributions" block.
Copy code
modules("java.instrument", "jdk.unsupported", "java.sql", "java.net.http", "java.desktop")
The documentation explains that in more detail. And set
Copy code
isEnabled.set(false)
in your ProGuard config block. You can later try to optimize that. Your above errors are all from ProGuard.
n
Thank you! Disabling proguard finaly led to understandable errors.
isEnabled.set(false)
followed by
runReleaseDistributable
made the same error popup happen, but at least I had the error logs on the console (
NoClassDefFoundError
). Adding
modules("java.instrument", "jdk.unsupported", "java.sql", "<http://java.net|java.net>.http", "java.desktop")
as specified here made
runReleaseDistributable
work. I would have never guessed I would have to add some JVM stuff in order to Ktor to work in some native target. Kotlin Multiplatform "Native" desktop is a lie then? We're just building "native" binaries invoking a JVM in the end? In the end the produced
.msi
is 70 Mo and once installed, it's 135 Mo. That's a lot! That's such a huge difference compared to the
.jar
produced by
packageUberJarForCurrentOS
which is 45 Mo. Do you know why is it so different? Anyway, thanks a lot for your help, I've read the documentation 3 times today but it's just so obscure to me 😞
c
you are using Compose Multiplatform to build your app, right? So Kotlin Multiplatform is native on many targets. Compose Multiplatform for Desktop is JVM and never claimed to be a “native” target. You should not mix up those 2 frameworks. there is also #CJLTWPH7S and its “sub” channels like #C01D6HTPATV for this kind of questions.