【问题标题】:Cordova plugin – class cannot be foundCordova 插件 - 找不到类
【发布时间】:2017-09-20 08:35:47
【问题描述】:

我正在尝试为 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 文件中的一些值,但似乎没有任何效果。

【问题讨论】:

  • 看看here。我认为您在 &lt;source-file&gt; 的声明中遗漏了一些路径

标签: android cordova cordova-plugins


【解决方案1】:

问题在于您如何在 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]);
};

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-07-22
  • 2018-01-02
  • 2013-06-27
  • 2013-10-13
  • 1970-01-01
  • 2017-11-12
  • 2016-04-24
相关资源
最近更新 更多