Cococ2D-X call native Android(JNI) and IOS method’s

Well we all like cross programming I guess and especially when it works 🙂
Here is a c++ class that can call JNI or IOS methods according to the running platform. With it you can execute any native (openUrl,market etc. ) function. Be sure to see the examples for Android and IOS.



Okay we have

  • One action that runs our Cocos2D-X application –
  • a helper class to call another Action(s) –
  • the Action that will be called by the heper class –
  • If you get error like method id not found check your method signature and if it doesent work make your method static

Notice the method I’ll be calling has one parameter and a return value both string. If you want to use another method like void with no return value you should change the method signature in NativeInterface.cpp, 4th parameter of JniHelper::getStaticMethodInfo


Well this is straight forward, we just have to provide a class like a bridge, which will be included only if the platform is IOS. In Xcode 4 for .mm extension just rename your .cpp file.

Recent Posts