compose-multiplatform icon indicating copy to clipboard operation
compose-multiplatform copied to clipboard

Resource file not added to distributed .msi installer

Open rottajuliano opened this issue 2 years ago • 6 comments

Pro project requires that a file cert.pem is read from the resources folder. When I distribute and install the application, i can see that the resource folder is empty and the certificate file was not copied during installations.

I'm following the guidelines present at https://github.com/JetBrains/compose-jb/tree/master/tutorials/Native_distributions_and_local_execution#packaging-resources

The file is currently at src > main > resources > common > cert.pem, and my build.gradle looks just like the example:

compose.desktop {
    application {
        mainClass = "TesterMainKt"
        nativeDistributions {
            modules("java.sql")
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
            packageVersion = "1.0.0"

            appResourcesRootDir.set(project.layout.projectDirectory.dir("resources"))
        }
    }
}

Any idea what im doing wrong here? I also tried moving the cert file to the root of the resources folder without success.

rottajuliano avatar Jul 15 '22 16:07 rottajuliano

Had the same problem and the only way I made it work was by using getResource. In my case I wanted to play a .wav file.

Maybe it may help you too 😉

GuilhE avatar Jul 21 '22 14:07 GuilhE

@rottajuliano you need to put your file cert.pem into a directory resources at the top level of your project with your current settings in your Gradle build file. You're referencing project.layout.projectDirectory.dir("resources") which is a direct subdirectory from the project directory. What you could also do is modify this to project.layout.projectDirectory.dir("src/main/resources") which should also work.

See here for a working sample project that includes a file from src/appdata: https://github.com/sebkur/test-compose-for-desktop/blob/0085bdff9086cfa9e69943342ed9f3c91c4a1f7c/build.gradle.kts#L78

There the directory used is located here: https://github.com/sebkur/test-compose-for-desktop/tree/0085bdff9086cfa9e69943342ed9f3c91c4a1f7c/src/appdata/common

sebkur avatar Sep 21 '22 10:09 sebkur

To clearify, you must put your resources into one of the described directories, not directly inside project/resources directory.

Say, your project directory is /home/someone/MyProjects/project1/. You may have different submodule such as /desktop, /android, /ios etc. Say, you want to include a resource for desktop only. So the correct configuration for /home/someone/MyProjects/project1/desktop/build.gradle.kts will be project.layout.projectDirectory.dir("resources"). Now the fact is, you must have to put your resources into one of these directories to be copied in release build:

  • /home/someone/MyProjects/project1/desktop/resources/common/
  • /home/someone/MyProjects/project1/desktop/resources/linux/
  • /home/someone/MyProjects/project1/desktop/resources/mac/
  • /home/someone/MyProjects/project1/desktop/resources/windows/
  • /home/someone/MyProjects/project1/desktop/resources/linux-x86/

fcat97 avatar Nov 17 '22 13:11 fcat97

I also encountered this issue, is there any other solution? The above method doesn't seem to work

Moriafly avatar Dec 06 '22 09:12 Moriafly

The resource folder does remain empty when you use the default location for resources. I also couldn't read resources after deployment. Then I found out (through debugging) that resources are case sensitive! When you debug your app resources are read directly from your hard drive which is case insensitive. Later it changes!

he-dev avatar Feb 22 '24 15:02 he-dev