I’m experimenting with JNI.
I found that the JDK includes tools to generate the JNI header files. In JDK 9 and earlier,
javah looks great. It work with bytecode, so we can compile Kotlin source into bytecode, then generate the JNI headers.
The Kotlin docs say (emphasis mine):
To declare a function that is implemented in native (C or C++) code, you need to mark it with the
external fun foo(x: Int): Double
The rest of the procedure works in exactly the same way as in Java.
javah was removed from JDK 10+, in favor of
javac only works on Java source code, so there seems to be no simple way to generate JNI headers from Kotlin code in the same way as we would do it in Java.
Is there any built-in support for generating JNI headers from Kotlin code, or any plans to add support for this? It seems like right now it’s necessary to decompile bytecode to Java in order to run
javac -h, or otherwise use the
javah tool from JDK 9 and earlier.