This is said static registration, so-called static registration, is the native method is directly through the method name of the specified format and the Java side of the Declaration code corresponding to the rules as follows:
Jniexport < return value > Jnicall java_< package path (. Change _) >_< class name >_< method name > (JNIENV *, jobject<, method parameters >)
Suppose the method Staticload () is declared in Hellojni, as follows:
Package Com.example.zhanghaiqiang.hellojni; Public class Hellojni { static{ system.loadlibrary ("main"); } Public native void staticload ();}
The corresponding native method is named
void Jnicall java_com_example_zhanghaiqiang_hellojni_androidjni_dynamiclog *, Jobject)
Of course, this rule does not need to rote, the JDK Javah automatically help us do this, CD to the Java directory, execute Javah < package path >.< class name >, the current directory will be generated in the corresponding Natvie class header file, For example, the above Hellojni, the com_example_zhanghaiqiang_hellojni_hellojni.h file content after executing Javah will look like this:
/*Do not EDIT this file-it are machine generated*/#include<jni.h>/*Header for Class Com_example_zhanghaiqiang_hellojni_hellojni*/#ifndef _included_com_example_zhanghaiqiang_hellojni_hellojni#define_included_com_example_zhanghaiqiang_hellojni_hellojni#ifdef __cplusplusextern "C" {#endif/** Class:com_example_zhanghaiqiang_hellojni_hellojni * method:staticlog * Signature: () V*/Jniexportvoidjnicall Java_com_example_zhanghaiqiang_hellojni_hellojni_staticlog (jnienv*, jobject); #ifdef __cplusplus}#endif#endif
The file is then copied to the default JNI directory, copy one and rename the. C or. cpp source file (you can also change the. h file to a source file directly), and then you can start writing the native method.
Static registration of Android JNI