I've been working on a project where I needed to expose Kotlin/Native code to the JVM through JNI.
The usual JNI workflow quickly gets annoying: you have to keep native implementations, JVM declarations, JNI names and signatures in sync manually. A mismatch often doesn't show up until runtime.
So I built kotlin-jni-interop.
The idea is to describe the JNI boundary in Kotlin itself:
kotlin @JniActual fun add(a: Int, b: Int): Int = a + b
and on the JVM side:
kotlin @JniExpect external fun add(a: Int, b: Int): Int
The Gradle plugin generates the JNI glue and packages the native library, while the compiler plugin can validate that both sides have matching signatures.
So instead of finding out about a broken JNI declaration with something like:
text java.lang.UnsatisfiedLinkError
you can catch the mismatch during the build.
I'm especially interested in feedback from people who have worked with Kotlin/Native + JNI in real projects.
GitHub: https://github.com/mimimishkin/kotlin-jni-interop
I'd be interested to hear whether this solves a problem you've actually encountered, and what you'd expect from a tool like this.
submitted by /u/Mimimishkin[link] [comments]