You cannot just use the public usb_init (); and then load such a native library, JNI is not implemented that way.
you use javah to create an .h file that you can use to create a library that implements certain native functions in the class.
javac USBManager
Creates a class file that you use with javah:
javah USBManager
This gives a file in this place with the name "USBManager.h", which indicates the functions to be implemented in .so / .dll that implement the corresponding native function.
#include <jni.h> /* Header for class USBManager */ #ifndef _Included_USBManager #define _Included_USBManager #ifdef __cplusplus extern "C" { #endif /* * Class: USBManager * Method: usb_init * Signature: ()V */ JNIEXPORT void JNICALL Java_USBManager_usb_1init (JNIEnv *, jobject); #ifdef __cplusplus } #endif #endif
So, you need to export a function called "Java_USBManager_usb_1init" that takes the specified parameters.
This function can be no more than:
JNIEXPORT void JNICALL Java_USBManager_usb_1init (JNIEnv *, jobject) { usb_init(); }
There is a pretty good simple example of a Sun developer blog , but there are many other examples there.
source share