I want to bundle a file along with my Kotlin Multiplatform library. The library supports both JVM and linuxX64 targets.
On the JVM, I am able to access a bundled file using MyClass::class.java.getResourceAsStream()
and friends.
But on linuxX64, how can we do this? We just need to get a path to the bundled resource. After that, opening a file and reading it should be easy.
Compose Multiplatform seems to have some solutions for bundling resources, as described here: https://github.com/JetBrains/compose-jb/blob/master/tutorials/Native_distributions_and_local_execution/README.md
But
I am also aware of projects such as moko-resource
, but it also doesn't have a solution for native libraries. It only supports apps on iOS, Android and Web.
Thanks.
Unfortunately KMM doesn't provide solution for this right now (and probably won't provide in the nearest future), it requires to create some kind of Resource Manager for Kotlin/Native. It is big architecture decision and looks like it is not priority right now. You can track progress for this in Kotlin's Youtrack.
As workaround you can create task that adds resources to .klib
in Gradle build of your library (.klib
already has special resources
folder that you could use for this, it is empty for non-JVM targets by default), but your library consumers should somehow pack those resources with the final executable (see example).