无法找到Cordova插件 -

时间:2017-09-20 08:35:48

标签: android cordova cordova-plugins

我正在尝试为cordova编写插件,当我尝试在Android设备上与它进行交互时,我不断收到此错误消息。

这是我的Java代码,我已经简化了。

package paypalhere;
//Lots of imports
public class paypalhereWrapper extends CordovaPlugin implements CardReaderConnectionListener, AuthenticationListener, TransactionController {
    @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
        if (action.equals("coolMethod")) {
            String message = args.getString(0);
            this.coolMethod(message, callbackContext);
            return true;
        }
        else if (action.equals("IntPPSDK")) {
            String token = args.getString(0);
            this.IntPPSDK(token);
            return true;
        }
        return false;
    }

    private void coolMethod(String message, CallbackContext callbackContext) {
        if (message != null && message.length() > 0) {
            callbackContext.success(message);
        } else {
            callbackContext.error("Expected one non-empty string argument.");
        }
    }

    private void IntPPSDK(String compositeAccessToken) {
        //stuff
    }

    //Stuff in here
}

这是我的Javascript界面​​包装

var exec = require('cordova/exec');

window.coolMethod = function (arg0, success, error) {
    console.log("coolMethod Called");
    exec(success,
         error,
         "paypalhere.paypalhereWrapper",
         "coolMethod",
         [arg0]);
};

window.IntPPSDK = function (token) {
    console.log("IntPPSDK Called");
    exec(function () {
            console.log("IntPPSDK Sucess");
         },
         function (x) {
            console.log("IntPPSDK Error - " + x.toString());
         },
         "paypalhere.paypalhereWrapper",
         "IntPPSDK",
         [token]);
}

这是我的plugin.xml

<?xml version='1.0' encoding='utf-8'?>
<plugin id="cordova-plugin-paypal-here" version="0.0.1" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
  <name>cordova-plugin-paypal-here</name>
  <js-module name="paypalhere" src="www/paypalhere.js">
    <clobbers target="window.paypalhere" />
  </js-module>
  <platform name="android">
    <config-file parent="/*" target="res/xml/config.xml">
      <feature name="paypalhere">
        <param name="android-package" value="paypalhere" />
      </feature>
    </config-file>
    <config-file parent="/*" target="AndroidManifest.xml" />
    <source-file src="src/android/paypalhereWrapper.java" target-dir="src/paypalhere" />
    <source-file src="src/android/paypalhereCallbacks.java" target-dir="src/paypalhere" />
    <framework src="src/android/paypalhere.gradle" custom="true" type="gradleReference" />
    <resource-file src="aar/PayPalHereSDK.aar" target="aar/PayPalHereSDK.aar" />
  </platform>
  <platform name="ios">
    <config-file parent="/*" target="config.xml">
      <feature name="cordova-plugin-paypal-here">
        <param name="ios-package" value="cordova-plugin-paypal-here" />
      </feature>
    </config-file>
    <source-file src="src/ios/cordova-plugin-paypal-here.m" />
  </platform>
</plugin>

有没有人知道为什么我会找到一个未找到课程的错误?我试过改变plugin.xml文件中的一些值,但似乎没什么用。

1 个答案:

答案 0 :(得分:0)

问题在于如何在plugin.xml中声明插件然后在Javascript界面​​中引用它。

plugin.xml更改为:

<feature name="paypalhereWrapper" >
    <param name="android-package" value="paypalhere.paypalhereWrapper"/>
</feature>

和Javascript界面​​:

window.coolMethod = function (arg0, success, error) {
    console.log("coolMethod Called");
    exec(success,
         error,
         "paypalhereWrapper",
         "coolMethod",
         [arg0]);
};