mirror of https://github.com/axmolengine/axmol.git
Use default class loader to obtain the ClassLoader for this NativeActivity
This commit is contained in:
parent
e67698116c
commit
dd79d9bbc2
|
@ -38,7 +38,6 @@ jclass _getClassID(const char *className) {
|
|||
|
||||
jstring _jstrClassName = env->NewStringUTF(className);
|
||||
|
||||
// explicit cast to jclass, since the returned object
|
||||
jobject _clazzObject = env->CallObjectMethod(cocos2d::JniHelper::classloader,
|
||||
cocos2d::JniHelper::loadclassMethod_methodID,
|
||||
_jstrClassName);
|
||||
|
@ -121,7 +120,7 @@ namespace cocos2d {
|
|||
|
||||
bool JniHelper::setClassLoaderFrom(jobject nativeactivityinstance) {
|
||||
JniMethodInfo _getclassloaderMethod;
|
||||
if (!JniHelper::getMethodInfo(_getclassloaderMethod,
|
||||
if (!JniHelper::getMethodInfo_DefaultClassLoader(_getclassloaderMethod,
|
||||
"android/app/NativeActivity",
|
||||
"getClassLoader",
|
||||
"()Ljava/lang/ClassLoader;")) {
|
||||
|
@ -136,7 +135,7 @@ namespace cocos2d {
|
|||
}
|
||||
|
||||
JniMethodInfo _m;
|
||||
if (!JniHelper::getMethodInfo(_m,
|
||||
if (!JniHelper::getMethodInfo_DefaultClassLoader(_m,
|
||||
"java/lang/ClassLoader",
|
||||
"loadClass",
|
||||
"(Ljava/lang/String;)Ljava/lang/Class;")) {
|
||||
|
@ -183,6 +182,40 @@ namespace cocos2d {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool JniHelper::getMethodInfo_DefaultClassLoader(JniMethodInfo &methodinfo,
|
||||
const char *className,
|
||||
const char *methodName,
|
||||
const char *paramCode) {
|
||||
if ((NULL == className) ||
|
||||
(NULL == methodName) ||
|
||||
(NULL == paramCode)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
JNIEnv *pEnv = JniHelper::getEnv();
|
||||
if (!pEnv) {
|
||||
return false;
|
||||
}
|
||||
|
||||
jclass classID = pEnv->FindClass(className);
|
||||
if (! classID) {
|
||||
LOGD("Failed to find class %s", className);
|
||||
return false;
|
||||
}
|
||||
|
||||
jmethodID methodID = pEnv->GetMethodID(classID, methodName, paramCode);
|
||||
if (! methodID) {
|
||||
LOGD("Failed to find method id of %s", methodName);
|
||||
return false;
|
||||
}
|
||||
|
||||
methodinfo.classID = classID;
|
||||
methodinfo.env = pEnv;
|
||||
methodinfo.methodID = methodID;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JniHelper::getMethodInfo(JniMethodInfo &methodinfo,
|
||||
const char *className,
|
||||
const char *methodName,
|
||||
|
|
|
@ -62,6 +62,11 @@ public:
|
|||
private:
|
||||
static bool cacheEnv(JavaVM* jvm);
|
||||
|
||||
static bool getMethodInfo_DefaultClassLoader(JniMethodInfo &methodinfo,
|
||||
const char *className,
|
||||
const char *methodName,
|
||||
const char *paramCode);
|
||||
|
||||
static JavaVM* _psJavaVM;
|
||||
static JNIEnv* env;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue