While making my first cross platform game using Cocos2d-x CPP version, I realized that it's so much easier to use C++ with Objective-C than to use C++ with Java. In iOS, I can simply name a .cpp file to .mm and include it in the project and I can call C++ or Objective-C methods right away. In Android, if I want to call a Java method from C++, I need to use JNI (Java Native Interface). For example, to call a static method named
AppActivity class, I need to do it like so.
The last argument of
getStaticMethodInfo is the method signature of the
share static method. This signature must be correct or else you'll get
Failed to find static method id error. To get this method signature, use
javap -s command from command line.