问题
I want to use below API which is at dalvik/vm/native/dalvik_system_DexFile.cpp:
static void Dalvik_dalvik_system_DexFile_defineClass(const u4* args, JValue* pResult)
static void Dalvik_dalvik_system_DexFile_openDexFile_bytearray(const u4* args, JValue* pResult)
But I don't know how can I include proper include files for using above two APIs in libdvm.so.
I tried to include whole headers in android project, but it failed with this compile error message: "Argument list too long".
Does anybody know what I should have to do for using above two APIs in libdvm.so? Thank you.
-- Added --
In dalvik/vm/native/dalvik_system_DexFile.cpp, there is some additional code to allow others to use static APIs.
const DalvikNativeMethod dvm_dalvik_system_DexFile[] =
{
{ "openDexFile", "(Ljava/lang/String;Ljava/lang/String;I)I", Dalvik_dalvik_system_DexFile_openDexFile },
{ "openDexFile", "([B)I", Dalvik_dalvik_system_DexFile_openDexFile_bytearray },
{ "closeDexFile", "(I)V", Dalvik_dalvik_system_DexFile_closeDexFile },
{ "defineClass", "Ljava/lang/String;Ljava/lang/ClassLoader;I)Ljava/lang/Class;", Dalvik_dalvik_system_DexFile_defineClass },
{ "getClassNameList", "(I)[Ljava/lang/String;", Dalvik_dalvik_system_DexFile_getClassNameList },
{ "isDexOptNeeded", "(Ljava/lang/String;)Z", Dalvik_dalvik_system_DexFile_isDexOptNeeded },
{ NULL, NULL, NULL },
};
I will call above 2 static API's like this:
dvm_dalvik_system_DexFile[1].fnPtr(args, &pResult);
回答1:
Those are the JNI implementions of the corresponding methods in the DexFile class. They would normally be called at the java level, by calling, e.g. the DexFile.defineClass() method, or at the JNI level, by using the normal JNI stuff for calling that java method.
Note however, neither of these methods are part of the public api, and you can't depend on them being present or having a particular prototype.
If you are wanting to load your own custom classes, look at the DexClassLoader class. Additionally, here's a related blog article about using DexClassLoader.
来源:https://stackoverflow.com/questions/12766774/how-can-i-include-proper-include-files-for-using-libdvm-so-at-my-shared-library