javah
has been deprecated since JDK 8 and will be/has been removed in JDK 10, and according to JEP 313 and the deprecation text, javac
with the -h
flag should be used instead:
Warning: The
javah
tool is planned to be removed in the next major JDK release. The tool has been superseded by the '-h' option added tojavac
in JDK 8. Users are recommended to migrate to using thejavac
'-h' option; see the javac man page for more information.
The problem is, javah
operates on compiled .class
files, while javac
operates on source files (i.e. .java
files.)
javah
works fine with Kotlin and external
functions, since everything ends up compiled as Java bytecode, but since there aren't any Java source files when using Kotlin, I don't see any way javac -h
could work.
Is there a javah
replacement, or a workaround, for Kotlin?
I recommend gjavap.
In the future I will also implement an easier-to-use command line tool which provides similar functionality to javap.
There is currently no built-in way to do this. There is an open issue for this on the Kotlin issue tracker that was raised in November 2019, but as of now it has not been prioritized and doesn't have a target version.
The only way to produce the header with JDK 10+ is to use javac -h
, which only works for Java source code, not Kotlin. I tested the method in How to solve missing javah in Java 10 – ugly way linked by Oo.oO, and it works as a workaround for now. The steps are:
javap
to decompile the bytecode back into Javanative
method definitions).javac -h
to produce the headerI'm thinking of writing a gradle script to do this (or hoping somebody else beats me to it!). If I manage to get it done, I'll update this post.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With