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);
|
jstring _jstrClassName = env->NewStringUTF(className);
|
||||||
|
|
||||||
// explicit cast to jclass, since the returned object
|
|
||||||
jobject _clazzObject = env->CallObjectMethod(cocos2d::JniHelper::classloader,
|
jobject _clazzObject = env->CallObjectMethod(cocos2d::JniHelper::classloader,
|
||||||
cocos2d::JniHelper::loadclassMethod_methodID,
|
cocos2d::JniHelper::loadclassMethod_methodID,
|
||||||
_jstrClassName);
|
_jstrClassName);
|
||||||
|
@ -121,10 +120,10 @@ namespace cocos2d {
|
||||||
|
|
||||||
bool JniHelper::setClassLoaderFrom(jobject nativeactivityinstance) {
|
bool JniHelper::setClassLoaderFrom(jobject nativeactivityinstance) {
|
||||||
JniMethodInfo _getclassloaderMethod;
|
JniMethodInfo _getclassloaderMethod;
|
||||||
if (!JniHelper::getMethodInfo(_getclassloaderMethod,
|
if (!JniHelper::getMethodInfo_DefaultClassLoader(_getclassloaderMethod,
|
||||||
"android/app/NativeActivity",
|
"android/app/NativeActivity",
|
||||||
"getClassLoader",
|
"getClassLoader",
|
||||||
"()Ljava/lang/ClassLoader;")) {
|
"()Ljava/lang/ClassLoader;")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,10 +135,10 @@ namespace cocos2d {
|
||||||
}
|
}
|
||||||
|
|
||||||
JniMethodInfo _m;
|
JniMethodInfo _m;
|
||||||
if (!JniHelper::getMethodInfo(_m,
|
if (!JniHelper::getMethodInfo_DefaultClassLoader(_m,
|
||||||
"java/lang/ClassLoader",
|
"java/lang/ClassLoader",
|
||||||
"loadClass",
|
"loadClass",
|
||||||
"(Ljava/lang/String;)Ljava/lang/Class;")) {
|
"(Ljava/lang/String;)Ljava/lang/Class;")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,6 +182,40 @@ namespace cocos2d {
|
||||||
return true;
|
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,
|
bool JniHelper::getMethodInfo(JniMethodInfo &methodinfo,
|
||||||
const char *className,
|
const char *className,
|
||||||
const char *methodName,
|
const char *methodName,
|
||||||
|
|
|
@ -62,6 +62,11 @@ public:
|
||||||
private:
|
private:
|
||||||
static bool cacheEnv(JavaVM* jvm);
|
static bool cacheEnv(JavaVM* jvm);
|
||||||
|
|
||||||
|
static bool getMethodInfo_DefaultClassLoader(JniMethodInfo &methodinfo,
|
||||||
|
const char *className,
|
||||||
|
const char *methodName,
|
||||||
|
const char *paramCode);
|
||||||
|
|
||||||
static JavaVM* _psJavaVM;
|
static JavaVM* _psJavaVM;
|
||||||
static JNIEnv* env;
|
static JNIEnv* env;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue