How to call native code from IntelliJ Plugin?

Answered

How example, I have a bunch of native libraries for several architectures:

mylib.dylib, mylib.so, mylib.dll

There are JNI bindings in the libs, which I want to call from the plugin itself, like this:

external fun hello(): Void

    companion object {
        init {
            System.loadLibrary("hello")
        }
    }

How example, I have a bunch of native libraries for several architectures:

mylib.dylib, mylib.so, mylib.dll

There are JNI bindings in the libs, which I want to call from the plugin itself, like this:

external fun hello(): Void

    companion object {
        init {
            System.loadLibrary("hello")
        }
    }

I want to distribute these libs among with .jar. I've tried to add binaries inside src folder and link them via Project Structure - Modules and Project Structure - Libraries with no result. Due to this issue, I can conclude that such a case should be possible. Should I add something inside build.gradle.kts? Or can I use c-interop somehow?

3 comments
Comment actions Permalink

Hi Alexandr,

Please try to place libraries in my-plugin/resources/lib directory.

1
Comment actions Permalink

Thanks! It worked out. But the libs are inside the .jar. I guess I need to unpack them and place in the java.library.path? I just saw some plugins which, when installed, immediately have the native libs in the Plugins folder.

0
Comment actions Permalink

There is no need to, the plugin class loader is able to load it from the lib directory. See:
com.intellij.ide.plugins.cl.PluginClassLoader.findLibrary()

for the details.

0

Please sign in to leave a comment.