I am trying to integrate an android library (.aar) into cocos2D Android release.
Though I can import the android library, I am not able to call the class function in the library.
This is how I call the Android function from the cocos2D javascript handler.
jsb.reflection.callStaticMethod('org/cocos2dx/javascript/myDialog', 'showAlertDialog', '(Ljava/lang/String;Ljava/lang/String;)V', 'MyAlert', 'This is my first Alert from cocos2d' )
Android library class
package org.cocos2dx.javascript;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
public class myDialog extends Activity {
private static myDialog cam = null;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
cam = this;
}
public static void showAlertDialog(final String title,final String message) {
Log.i(title, message);
//we must use runOnUiThread here
cam.runOnUiThread(new Runnable() {
@Override
public void run() {
AlertDialog alertDialog = new AlertDialog.Builder(cam).create();
alertDialog.setTitle(title);
alertDialog.setMessage(message);
alertDialog.show();
}
});
}
}
below is the console warning I get
2020-07-01 16:47:46.514 26242-26339/org.cocos2d.demo E/JavaScriptJavaBridge: [ERROR] (C:/start_project/build/jsb-default/frameworks/cocos2d-x/cocos/scripting/js-bindings/manual/JavaScriptJavaBridge.cpp, 598): call valid: 0, call.getArgumentsCount()= 2
2020-07-01 16:47:46.514 26242-26339/org.cocos2d.demo E/JavaScriptJavaBridge: [ERROR] Failed to invoke JavaScriptJavaBridge_callStaticMethod, location: C:/start_project/build/jsb-default/frameworks/cocos2d-x/cocos/scripting/js-bindings/manual/JavaScriptJavaBridge.cpp:604
I have been working on this for 3 days now. But could not find any solution. Any kind of help will be fairly appreciated
The documentation for the same Calling java function from cocos2d The documentation is fairly simple and has been followed likewise with no success.