Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

easiest way to generate files in jni folder android

I am wondered if there is a way to generate the .h files in the jni folder easier than command like this

javah -jni -classpath bin/classes/ -d jni/ com.example.test_ndk.FibLib

I mean I want to automate this step so I have to write only

public native static long fibNR(long n);

and then eclipse will generate the .h files in jni folder for me

How can I do that ?

like image 560
Mohammed Subhi Sheikh Quroush Avatar asked Dec 29 '25 18:12

Mohammed Subhi Sheikh Quroush


1 Answers

Option 1:

If it makes a difference, you do not have to include the -jni option. It's the default option for javah.

javah -classpath bin/classes/ -d jni/ com.example.test_ndk.FibLib

Option 2:

The other alternative would be to create the header file yourself, but this is not an easier option. Your header would look like this (there's a 1 before ndk in test_1ndk because you used an _ character in the package name. If we don't put it, the caller will look for a folder called ndk inside a folder called test, therefore, I wouldn't recommend using test_ndk as your package name. Instead use testNdk or something with the underscore):

#include <jni.h>
JNIEXPORT jlong JNICALL Java_com_example_test_1ndk_FibLib(JNIEnv*, jclass, jlong);
// use jobject instead of jclass if your method is non-static

And the general format is:

JNIEXPORT [returnType] JNICALL Java_[package name with folders separated by _]_[class name]_[method name] (JNIEnv*, jclass, jtype arguments);
like image 156
naxchange Avatar answered Jan 01 '26 06:01

naxchange



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!