jni/../../Classes/AppDelegate.cpp:79: error: undefined reference to 'TestFun::TestFun()' jni/../../Classes/AppDelegate.cpp:80: error: undefined reference to 'TestFun::getBundleID()' jni/../../Classes/AppDelegate.cpp:83: error: undefined reference to 'TestFun::getStringWithParams()' collect2: error: ld returned 1 exit status
AppDelegate 文件中修改 #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) auto myClass = new TestFun(); std::string myStr = myClass->getBundleID(); cocos2d::log("bundle id is %s",myStr.c_str()); <!-- 新添加 getStringWithParams --> std::string returnStr = myClass->getStringWithParams(); cocos2d::log("return str is %s",returnStr.c_str()); #endif
java 文件添加函数
public static String getMyString(String s) { Log.d("c++ call getMyString params is ",s); return"return form java "; }
Android.mk 文件 依然依旧 ../../Classes/Test.cpp \
编译通过
adb logcat c++ call getMyString params is ----> java 文件内容 std::string toJavaStr = "from c++ params"; ----> c++文件传递给java D/c++ call getMyString params is ( 1794): from c++ params D/cocos2d-x debug info( 1794): return str is return form java
local luaBridge = require("cocos/cocos2d/luaj") local ok, ret = luaBridge.callStaticMethod("org/cocos2dx/lua/AppActivity", "isWXAppInstalled", nil, "()Z")