I need help with jni

I need help with jni
0.0 0


Hi guys!
Sorry for my broken English.
I have not figured out to work with JNI! Please help!
I have java class for example:

class Sample {
public static int sum(int a, int b) {
return a + b;

By javah i do Sample.h, I connect it to the project.

As I understand it, then I have to create Sample.cpp which describe the method jni_onload (), getmethodid (), getsum ();

Further difficulties arise (:

In the example in the method SimpleAudioEngineJni.cpp getmethodid () is a line:
classOfCocos2dxActivity = env-> FindClass (“org/cocos2dx/lib/Cocos2dxActivity”);
I describe my class? or in the class Cocos2dxActivity describe all methods of class Sample?!

If you have somebody, a detailed description will be very grateful!


I know how to create header and how to call java method from c + +, but I do not understand how this is implemented in cocos2dx?!


If you are calling java method from native GLThread, you can use JniHelper class in cocos2d-x to help you calling
java static methods.


Thank you very much, take care of the JNI :slight_smile:


I need to do the same call a method form Java class Cocos2dxActivity on AppDelegate.cpp, do you solve the problem ?? do you know how to do that ??

Please Help me