Integrate Openfeint into cocos2d-x for android

Hello,

I read Simon Lin’s guide on how to integrate openfeint into android (http://blog.molioapp.com/2011/11/openfeint-and-admob-integrated-with.html) 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?

Thanks!

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"
#include 

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

#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#include "platform/android/jni/JniHelper.h"
#include 
#define CLASS_OPEN_NAME "org/cocos2dx/lib/OpenFeintUtils"
#endif

And call java function:

void OpenFeint::showLeaderboard()
{
    #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    JniMethodInfo methodInfo;
    if (! JniHelper::getStaticMethodInfo(methodInfo, CLASS_OPEN_NAME, "showLeaderboard", "()V"))
    {
        CCLog("Can't not find static method showLeadboard");
        return;
    }

    methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID);
    methodInfo.env->DeleteLocalRef(methodInfo.classID);
    #else
    CCLog("click show");
    #endif
}

Just do it. You must creat OpenFeintUtils.java 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 Android.mk or anything because of the JniHelper.h and jni.h?

of course, you need to add RunJava.cpp to Android.mk 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 :