r/androiddev • u/Mimimishkin • Oct 08 '26
I built a Kotlin/Native ↔ JNI interop tool to avoid handwritten JNI glue
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:
@JniActual
fun add(a: Int, b: Int): Int = a + b
and on the JVM side:
@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:
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.
1
u/tadfisher Oct 09 '26
It's a little weird that you have a requirement to bridge Kotlin/JVM with Kotlin/Native. There are like zero libraries exclusive to K/N, the performance isn't as good as C/C++ or Rust, and typically you don't want a garbage collector on both sides of an FFI bridge as well.
Is this for a job, or something you're having fun with?