Hi guys, how to call (use) lib/x64 and lib/x86 example.dll files on compose multiplatform desktop?
j
Hi guys, how to call (use) lib/x64 and lib/x86 example.dll files on compose multiplatform desktop?
m
You can use JNI if you control the source code, or JNA if you want to call into native C APIs without changing them.
j
I am using JNI. Where should I store the .dll files? I’m currently store .dll files in the resources folder. However, it cannot find the files. no libamtsensorcore.dll in java.library.path: [/Users/javokhir/Downloads/demo/build/classes/kotlin/jvm/main, /Users/javokhir/Downloads/demo/build/processedResources/jvm/main]
@mikehearn
m
@Javokhir Savriev This is unfortunately quite a convoluted topic. As the error says it's looking through a path stored in the
java.library.path
system property. So you have to pass the directory where the libraries are found with that
-Djava.library.path=$dllDir
. But watch out - that dll dir will be in your local build tree. You will also need to handle this at runtime. At that point how it's done will depend on your packaging solution. With Conveyor for example you can just add them as inputs. They will end up in the right place, be code signed and be located automatically at runtime. If you don't use it then you will need to arrange some other approach. I should write up some better docs on all this at some point for people.
Note that you normally don't pass file extensions to
loadLibrary
.
A different approach is to pass the absolute path to
System.load
.
a
I don't know how exactly, but it would be awesome if there was some sort of fast-path to doing this if the library you were including (via maven/gradle) was a KMP/Native library, then the KMP application would understand it, and load the correct dll for you or something.
m
It doesn't have to be a KMP specific solution. The JVM ecosystem in general needs better support for native libraries and for Kotlin/Native users that better support would flow through naturally anyway.
336 Views