https://kotlinlang.org logo
i

ishitatsuyuki

02/13/2022, 9:59 AM
I'm seeing mentions of JNI in https://github.com/JetBrains/kotlin/blob/f5e4c72f063608220d64da81e0fc6be5c17505fc/[…]etbrains/kotlin/native/interop/gen/SimpleBridgeGeneratorImpl.kt Does this mean that the interop tool actually has partial support for JVM bindings?
Looks like this code is as old as cinterop was introduced, it seems to remained an internal thing for a long while. Additional user discussions: https://old.reddit.com/r/Kotlin/comments/gs42vh/kotlinnative_to_avoid_jni/fs3rk5x/
l

Landry Norris

02/13/2022, 2:22 PM
I've gotten JNI to work pretty easily by using the CName annotation and matching the CName of the method with the name Java expects. It would be nice if, when my code in in the same project, there was some annotation like JNI(KClass) that would recognize the name Java expects for a JNI method and set the String for me.
Especially since I prefer to use JNI in static classes so the names are always something like com_example_modulename_JniBridge_Companion0012 or something like that. It would be nice to just put an annotation like JNI(JniBridge::class)
i

ishitatsuyuki

02/13/2022, 2:25 PM
Is that for JVM-specific bindings? Ideally I want to share code between Native and JVM bindings
l

Landry Norris

02/13/2022, 2:26 PM
That is for when I have native and JVM code in the same project, and I want to be able to bind the native to Java calls via JNI.
👀 2
8 Views