Game finished, to publish to the various platforms, iOS, Android is definitely not, then this article on Android platform docking agent Billing SDK, channels, five operators, advertising, sharing, data statistics and so on the JNI call, the SDK is really all kinds of trouble ah ...
First of all, so many SDKs, features are different, so there must be a unified SDK management class to manage, and then the game need to use what function when the call to the specified interface, interface implementation, different platforms in the call sdk~
Then, C + + calls the Java layer: (Take display ads for example)
====================================//c++//====================================//com/ican/redstar/---> The path of the called Class (the package name can be different from the absolute pathname) //redstarsdkmanager---> class name//SHOWYCAD ---> Interface name to invoke//() V ---> Return value void parameter void#define class_name "Com/ican/redstar/redstarsdkmanager" #if cc_target_platform = = Cc_platform_ Androidjnimethodinfo t;if (Jnihelper::getstaticmethodinfo (T,class_name, "Showycad", "() V")) {t.env-> Callstaticvoidmethod (T.classid, T.methodid); T.env->deletelocalref (T.CLASSID);} Else{cclog ("C + + call Java Showycad faild!");} #endif//========================================//java//========================================public Static void Showycad () {log.d ("Ycad", "Call from Cocos2d-x ..."); Try{yccpmanager.getinstance (). SHOWCP (GetContext (). Getapplicationcontext ());} catch (Exception e) {log.d ("Ycad", "show CP thow uncaught Exception");}}
Yes, very simple ~, of course, if you want to pass a parameter, or the function has a return value, it will be a little more complicated, and finally to discuss, first look at the Java layer out of C + +
==============================//java//==============================//directly declare a native method, such as user login return//jni callbackprivate static native void Loginendcallback (int loginsuccess, String usename);//============================= =//c++//==============================//Login Callback//com_ican_redstar_redstarsdkmanager---> Path, class name, function name are underlined// Jniexport void Jnicall java_com_ican_redstar_redstarsdkmanager_loginendcallback (jnienv *env, Jobject thiz, Jint Loginsuccess, jstring usename) {Jboolean jb_copy = false;string nameStr = string (Env->getstringutfchars (UseName, &jb_copy)); int sec = loginsuccess; Cclog ("%s jni called True [login =%d, UserName =%s]", __function__, sec, Namestr.c_str ()); Redstarsdkmanager::getinstance ()->logincallback (sec, nameStr);}
Great, Java tune C + + is also simple.
Finally, let's take a look at parameter passing, and return with the function:
Learn from other friends of the blog, Lunch break ~
Http://www.blogjava.net/china-qd/archive/2006/04/29/44002.html (Explanation of parameter passing)
http://blog.csdn.net/luxiaoyu_sdc/article/details/15874505 (Detailed Cocos2d::jnihelper)