两个宏 用于创建注册native方法的数据结构,注意每一项的内容
如NATIVE_METHOD(DexFile, getOatPath,
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;"), 展开之后的内容
"DexFile","(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)",DexFile_getOatPath(函数指针)
_
#ifndefNATIVE_METHOD
#defineNATIVE_METHOD(className,functionName,signature) \
{ #functionName,signature,reinterpret_cast(className ## _ ## functionName) }
#endif
#defineREGISTER_NATIVE_METHODS(jni_class_name) \
RegisterNativeMethods(env, jni_class_name, gMethods, arraysize(gMethods))
REGISTER_NATIVE_METHODS用于注册函数指针到相应的类,签名里面包含参数和返回值,gMethods里面包含函数指针签名,可以通过函数指针调用函数,并且这里将函数指针和java类绑定(通过jni_class_name绑定类)
staticJNINativeMethod gMethods[] = {
NATIVE_METHOD(DexFile, closeDexFile,"(Ljava/lang/Object;)V"),
NATIVE_METHOD(DexFile, defineClassNative,
"(Ljava/lang/String;Ljava/lang/ClassLoader;Ljava/lang/Object;)Ljava/lang/Class;"),
NATIVE_METHOD(DexFile, getClassNameList,"(Ljava/lang/Object;)[Ljava/lang/String;"),
NATIVE_METHOD(DexFile, isDexOptNeeded,"(Ljava/lang/String;)Z"),
NATIVE_METHOD(DexFile, getDexOptNeeded,
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)I"),
NATIVE_METHOD(DexFile, openDexFileNative,
"(Ljava/lang/String;Ljava/lang/String;I)Ljava/lang/Object;"),
NATIVE_METHOD(DexFile, getImageInfoChecksum,
"()J"),
NATIVE_METHOD(DexFile, getApkChecksums,
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)[J"),
NATIVE_METHOD(DexFile, getOatPath,
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;"),
NATIVE_METHOD(DexFile, getOatPathInDataDalvikCache,
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;"),
};
voidregister_dalvik_system_DexFile(JNIEnv* env) {
REGISTER_NATIVE_METHODS("dalvik/system/DexFile");
}