Is the guide for generating an .exe lost? I can't ...
# compose-desktop
p
Is the guide for generating an .exe lost? I can't find it anywhere. I have the project, which can execute under android studio, but can't find anywhere explained the steps to generate a .exe with java included inside. I searched on: https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-native-distribution.html https://github.com/JetBrains/compose-multiplatform/tree/master/tutorials google here etc... In the first link they explain how to configure gralde.... but they forgot to explain where I should press for generating the exe file.
s
By default compose uses jlink to create the binaries through the
createDistributable
gradle task (which produces the binaries in
${project.buildDir}/compose/binaries
), but this doesn't create a fully bundled application packaged into an exe (afaik). For this option make sure to specify the target format:
Copy code
compose.desktop {
    application {
        nativeDistributions {
            targetFormats(TargetFormat.Exe)
        }
    }
}
In order to do that I highly recommend to use conveyor, they make it easy peasy to create native distributions that comes with an app installer and automatic update support.
p
you still didn't tell me how to create the exe
that line you wrote me is also on those links
"create the binaries through the
createDistributable
gradle task"
where is that?
I openned gradle window on android studio and didn't find any task called createDistributable
there is only one task called "composeTest"
s
Android studio by default hides a lot of gradle tasks for "optimisation purposes", you can either execute it from the cmdline or enable all gradle tasks. Or open it in intellij.
p
enable all gradle tasks whould be preferable, to have it in a button
do you know how to do it?
s
I suppose ticking this box should do it (from stackoverflow):
Might depend on your android studio version
p
thanks, on the other hand I need a clarification on the embedded java to make .exe autorunnable without java installed
when I first created a compose for deskop application two years ago (I think) I remember to generate the .exe file with java inside automatically without using external software like conveyor
is not possible anymore?
i don't wanna create a installer
just a .exe file with java embedded to be able to be executed on windows without java installed
c
The plugin simplifies the process of packaging applications into native distributions using
jpackage
and running an application locally. Distributable applications are self-contained, installable binaries that include all the necessary Java runtime components, without requiring a JDK to be installed on the target system.
https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-native-distribution.html#gradle-plugin
s
I may be wrong I don't personally use it because of limitations of jpackage, but maybe try running the gradle task I mentioned and see what it produces, maybe it is sufficient for your needs 🙂
☝🏼 1
p
yes!, thanks both of you, at this exact point I can't run it, I'm getting an exception
Failed to check JDK distribution: 'jpackage.exe' is missing
I think that it's because the embedded jdk in Android Studio doesn't contain all the stuff necessary for doing this. I'm searching for a standalone open jdk to solve this. After the dinner I'll try. Thank you.
👍 1
it worked, now I have to learn reading the documentation how to reduce the size of the embedded java... 150 Mb is too much :D
s
You can configure which modules to include in the gradle plugin (https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-native-distribution.html#including-jdk-modules), can also use proguard to reduce code though that wont affect the bundled JRE
p
well, in that part of the guide they don't say how to do it
To reduce the distributable size, the Gradle plugin uses jlink that helps bundle only the necessary JDK modules.
For now, the Gradle plugin does not automatically determine necessary JDK Modules.
they say they use jlink to reduce modules, but they are not using it automatically
so every module is added
they say that that you can specify which modules you want, but they don't specify how to remove modules
m
Just in order to avoid any confusion. The “exe” which you can create here is not a single exe-file which you can use to run your application. Instead it is an exe installer which you can execute to install the application. I personally prefer to create an MSI installer instead but in the end this is probably just a matter of taste.
p
Michael, you mean with convey? or with Android Studio?
I achieved to create the exe with android studio without convey, and unfortunatelly it creates a exe with 500kb and two folders with 80 megabytes each that must be placed on the same folder than the exe. I whould prefeer a simple exe with all embedded inside.
on the other hand, I tryed to create a MSI with android studio, and I can't I have this gradle:
Copy code
compose.desktop {
    application {
        mainClass = "com.helper.MainKt"

        buildTypes.release.proguard {
            obfuscate.set(true)
        }

        nativeDistributions {
            targetFormats(TargetFormat.Msi, TargetFormat.Exe)
            packageName = "Helper"
            packageVersion = "1.0.0"
        }
    }
}
When I execute
.\gradlew createDistributable
only a folder with the .exe file is created, but I can't find any .msi file anywhere. I also tryed removing TargetFormat.Exe and letting only TargetFormat.Msi with same result.
m
1. I am talking about the standard Compose Gradle tasks. 2. You are calling the wrong task. Call
.\gradlew packageDistributionForCurrentOS
instead. This will create all configured targetFormats. (Maybe restrict yourself to MSI here.) 3. Once everything works you should switch to
.\gradlew packageReleaseDistributionForCurrentOS
. That’s where ProGuard kicks in and tries to reduce the bundle size. But don’t try that before everything else works. You will find the installer as a single file under
YourApp/composeApp/build/compose/binaries/main/msi
p
thank you Michael, the second command doesn't work, probably it's failing because I need to add some rules in proguard to avoid breaking my libraries (retrofit etc... are giving a lot of proguard missing files warning)
on the other hand, I found another issue, with your first command, it successfully generates the installer, and it installs on program files folder, but doing that breaks the application, because it stores a database on the project folder and also unzips content selected from a file picker, on the project folder also, and it seems that it doesn't have permissions to do it and fails. Any idea how to deal with this? it seems that also datastore is not working neither
m
This sounds like a problem with your program logic and not so much like an installation problem. Your program should define an accessible application directory where such things are stored. A common practice is to create a hidden folder like .MyAppsFiles in the users home directory. You could also use a library like this https://github.com/psuzn/multiplatform-paths to get the platform specific locations for such files.
p
is preferable to create a folder inside AppData?
m
Which “AppData” are you talking about?
p
C:\Windows\user\username\AppData\Local\AppName
m
But that’s only valid for Windows. Other platforms have other rules.
p
yep
I think that repo has an error
AppData has three subfolders
Local, LocalNow and Roaming
and the application data is stored in one of these subfolders
not on AppData directly
m
Sorry, I am on Mac and so can’t verify that. But I think you got the point.
p
yes, thank you
well, almost everything seems to work with the change you propossed, everything but data store
if I execute the program on android studio, it successfully creates the
app.preferences_pb
file on appdata and it works, but if I create a distributable installer and install it, then, i see that it creates a temp file called
app.preferences_pb.tmp
but that file has 0 bytes and datastore is not storing or retrieving any values
any idea why?
I openned a new thread for it, as it seems a completly different topic, and probably will help other persons in the future to have it isolated