JNI to Communicate with Java Class

JNI to Communicate with Java Class
0.0 0



I’m new to Cocos2d-X C++ programming. Now I’m in a situation that i have to make communication with the java classes to implement the AI for my game.

But I don’t understand the JNI concept at all. I’ve searched all over the internet and our forum. But couldn’t even get a single clue to solve my problem.

I’ve tried this tutorial too.

So point me to some tutorial or sample code will be much appreciated.

Thanks in advance.


Refer to SimpleAudioEngineJni.h , SimpleAudioEngineJni.cpp , SimpleAudioEngine.cpp :slight_smile:


Thanks for the reply. But to which .java file these SimpleAudioEngine.cpp is communicating??


Hello Nitest Purohit. Thanks for the hint. I got it working :slight_smile:


maybe you can check this one : http://www.himigame.com/android-game/725.html,
or just look at the hello world android project with cocos2d-x


Dinesh S Kannan : :slight_smile:


R J That link is in chinese :frowning:


Nitesh Purohit wrote:

Dinesh S Kannan : :slight_smile:

I thought you were Chinese…

You can get help from google.

When create a android project ,in folder “jni”> “helloworld”>“main.cpp”

void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h)

and you can check the java file “Cocos2dxRenderer” in package “org_cocos2dx_lib” ,and there is a native function “nativeInit” ,and I think you will understand…

The chinese page I sent you is also useful,and You can use google translate……


R J: Thanks got it…