Home > Net >  How to call native code from IntelliJ Plugin?
How to call native code from IntelliJ Plugin?

Time:07-21

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?

CodePudding user response:

I'd connected with Idea developer and he said that native libs should be placed inside following folder.

myplugin/main/resources/lib

That's way libs will be copied to .jar. To unpack lib from the .jar I'm using this library. You must rewrite it in Kotlin and place classes inside plugin codebase. Also remove Logger library, as it will break Sandbox. Be aware of abstract properties in DefaultJNIExtractor, as Java-to-Kotlin converter fails on this piece.

  • Related