Integrate Openfeint into cocos2d-x for android

Integrate Openfeint into cocos2d-x for android
0.0 0



I read Simon Lin’s guide on how to integrate openfeint into android ( and I got the gist of it:

~~Call a JNI function from Java side which allows JNI to save the JNIEnv for later use in c++
~~c++ calls the JNI functions with the saved-in-memory JNIEnv variables.
-JNI calls Java, which calls the openfeint SDK and API.

But I do not get how does cocos2dx call the JNI functions (step two). In the guide, they had it defined as static methods in a class, but how do you reference it from your cocos2d-x games? Am I missing something in the Android .mk files? I do not know how to make them connect together (cocos2d-x and JNI). Can anyone help me with this?


Use Jni in android.

In cocos2d-x 0.12, look at main.cpp on cocos2d-x project/androi/jni/helloworld/, you can see:

#include "platform/android/jni/JniHelper.h"

I use it, and create a RunJava.cpp :
Set include:

#include "platform/android/jni/JniHelper.h"
#define CLASS_OPEN_NAME "org/cocos2dx/lib/OpenFeintUtils"

And call java function:

void OpenFeint::showLeaderboard()
    JniMethodInfo methodInfo;
    if (! JniHelper::getStaticMethodInfo(methodInfo, CLASS_OPEN_NAME, "showLeaderboard", "()V"))
        CCLog("Can't not find static method showLeadboard");

    methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID);
    CCLog("click show");

Just do it. You must creat with method “showLeaderboard”.
Only need to include “JniHelper.h” and “jni.h”, and you can call java method like me


Thanks for your reply!

So you do not need to add your RunJava.cpp to or anything because of the JniHelper.h and jni.h?


of course, you need to add RunJava.cpp to to make Cygwin build it.
Don’t need anything more with JniHelper.h and jni.h


It’s good to see the new cocos2d-1.0.1-x-0.12.0 do much things about JNI calling.

If you don’t want to re-write all the codes, you can refer my another post about this.

I just faced this new JniHelper architecture and already adopt to it.

Here is the reference link :