1、Java与C++混合编写:
使用JNI(Java本地调用)
实例:cocos2dx/platform/android/jni对应目录cocos2dx/platform/android/java
const char* getConstStrRetuen(const char* funcName)
{
JniMethodInfo t;
std::string ret;
if (JniHelper::getStaticMethodInfo(t, "org/cocos2dx/lib/Cocos2dxHelper", funcName, "()Ljava/lang/String;"))
{
jstring retFromJava = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID);
const char* str = t.env->GetStringUTFChars(retFromJava, 0);
ret = str;
t.env->ReleaseStringUTFChars(retFromJava, str);
t.env->DeleteLocalRef(t.classID);
}
return ret.c_str();
}
const char* getDEVICENAME()
{
return getConstStrRetuen("getDeviceName");
}
如上,调用JniHelper::getStaticMethodInfo(JniMethodInf