我正在开发一个使用VS2015的JS/Cordova应用程序。 我使用Android Studio开发了一个本地代码库(libmyjni.so)。 我想为Android创建一个Cordova插件,它将使用我的.so库。如何使用VS2015添加cordova插件.so文件?
我假设我需要添加此.so文件到我的插件代码(或这是包装一些其他的方式?)
我的问题是,在那里我会将此机库(的.so)下插件文件夹,所以插件代码(.java)文件可以调用它的方法?除此之外还需要其他设置吗?
眼下,文件夹/文件结构看起来像
plugins
--example.plugin.calculator
----src
------android
--------Calculator.java //this is using the method in the .so library
----www
------calculator.js
----plugin.xml
此外,在我的插件类我将如何加载.so库 - 在pluginInitialize方法或静态方法 ?
目前我的插件类看起来是这样的:
package example.plugin.calculator;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.PluginResult;
import org.json.JSONObject;
import org.json.JSONArray;
import org.json.JSONException;
public class Calculator extends CordovaPlugin {
protected void pluginInitialize() {
System.loadLibrary("myjni"); //contains the "average" method
}
public static final String ACTION_AVERAGE = "average";
@Override
public boolean execute(String action, JSONArray args,
CallbackContext callbackContext)
throws JSONException {
if (ACTION_AVERAGE.equals(action)) {
JSONObject arg_object = args.getJSONObject(0);
String n1 = arg_object.getString("n1");
String n2 = arg_object.getString("n2");
double answer = average(n1, n2);
String result = String.valueOf(answer);
callbackContext.success(result);
return true;
}
callbackContext.error("Invalid action");
return false;
}
public native double average(int n1, int n2);
static {
System.loadLibrary("myjni"); //contains the "average" method
}
}
任何帮助非常赞赏, _Thanks
你解决了这个问题吗?我面临同样的问题。的System.loadLibrary( “myjni”);不行。请帮帮我 – dalvir