I'm creating cocos2d-x game (v. 3.4) on mac os using android sdk 4.2.2, but I tried other too. I want to make NativeHelper class to call some native android stuff from c++. I used this tutorial as the base: http://www.cocos2d-x.org/wiki/User_Tutorial-Integrate_AdMob It's working, but I want use a java function with parameters. And there comes errors:
02-13 09:33:20.690: W/dalvikvm(28873): Bogus method descriptor: (I;)V 02-13 09:33:20.690: E/JniHelper(28873): Failed to find static method id of showBanner
Here's java implementation:
public static void showBanner(int position) {
final int _position = position;
_appActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
if(_appActivity != null){
if (!_appActivity.adView.isEnabled()){
_appActivity.adView.setEnabled(true);
}
if (_appActivity.adView.getVisibility() == View.INVISIBLE){
_appActivity.adView.setVisibility(View.VISIBLE);
RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
if(_position == 0){
adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
}
else{
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
}
_appActivity.adView.setLayoutParams(adParams);
}
}
}
});
}
c++ implementation:
void NativeHelper::showBanner(int position){
cocos2d::JniMethodInfo t;
if (cocos2d::JniHelper::getStaticMethodInfo(t, AppActivityClassName, "showBanner", "(I;)V")){
t.env->CallStaticVoidMethod(t.classID, t.methodID, position);
t.env->DeleteLocalRef(t.classID);
isBannerShowing = true;
}
}
If I just remove position parameter from both function (and change (I;)V to ()V ) it's working like a charm. I tried other parameter types like bool and it also doesn't work.
I thought I maybe did something wrong so I found this tutorial: http://stnguyen.com/cocos2d-x/call-java-functions-from-cpp.html
And calling for example sayHello also doesn't work too:
02-13 09:33:16.955: W/dalvikvm(28873): Bogus method descriptor: (Ljava/lang/String;I;)V 02-13 09:33:16.955: E/JniHelper(28873): Failed to find static method id of sayHello
I'm using ndk r9, but tried r10 too. I'm basically out of ideas...
You mistyped. It should be "(I)V", not "(I;)V"