我使用JniHelper来调用Android中的方法,通过搜索,做了前期的各项准备工作
引入文件到项目中:
Javajdk1.6.0_30includejni.h
Javajdk1.6.0_30includewin32jni_md.h
include:
#if(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include “platformandroidjniJniHelper.h”
#endif
调用代码:
extern “C” {
void GameLevelScene::TestJNI() {
JniMethodInfo jmi;
if(JniHelper::getMethodInfo(jmi, “com/maklon/game”, “checkF”, “(Ljava/lang/String;)V”)) {
CCLog(“checkF method is exist”);
jstring StringArg = jmi.env->NewStringUTF(“A”);
jmi.env->CallVoidMethod(jmi.classID, jmi.methodID, StringArg);
} else {
CCLog(“not find static method”);
}
}
}
但在编译时,却报如下错误:
错误 11 error LNK2019: 无法解析的外部符号 “__declspec(dllimport) public: static bool _cdecl cocos2d::JniHelper::getMethodInfo(struct cocos2d::JniMethodInfo &,char const *,char const *,char const *)” (url),该符号在函数 “public: void __thiscall GameLevelScene::TestJNI(void)” (url) 中被引用
网上搜索相关的错误实在太少,不知道是缺少了什么步骤或在哪个环节上有错,还望指教。