Inside `"src/jvmMain/resources"` I’ve my resources...
# compose-desktop
g
Inside
"src/jvmMain/resources"
I’ve my resources. If I run
./gradlew run
the app launches and I can use them, example:
playSound(File("src/jvmMain/resources/sound.wav"))
. But when I create a distribution or a package those resources aren’t included. I can see them inside
build/processedResources
but not in
/build/compose/binaries/main/app/MyApp.app/Contents/app/resources
. I’ve tried this:
Copy code
with(project.file("src/jvmMain/resources")) {
    macOS { iconFile.set(resolve("icon.icns")) }
    linux { iconFile.set(resolve("icon.png")) }
    windows { iconFile.set(resolve("icon.ico")) }
    appResourcesRootDir.set(project.layout.projectDirectory.dir(this.path)) //<<<<<<<<<<<<<
}
But with no luck, still can’t “find them”. Funny thing, the icons (
iconFile
) are found and used 🤷‍♂️ Any hint? Thanks. I was looking into this docs.
m
You cannot load resources in Java that way. You should use one of Class::getResource or Class::getResourceAsStream but the linked documentation is clearly saying that. And then your path is wrong too. It should be just
/sound.wav
without the
src/jvmMain/resources
part.
g
Thanks for your reply, but I’m interested in the second approach:
Adding files to packaged application
And thus my question, what am I doing wrong because I can’t see files under an installation directory.
m
Sorry, but I cannot help you with the second approach. If done right, the first approach works nicely with minimum effort for desktop and Android. So I use it all the time.
👍 1
👍🏻 1