2017-09-20 6 views
0

私はcordovaのプラグインを作成しようとしています。アンドロイドデバイスでプラグインを試してみると、このエラーメッセージが表示され続けます。Cordovaプラグイン - クラスが見つかりません

ここに私の簡略化した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ファイルのいくつかの値を変更しようとしましたが、何も動作していないようです。

+0

は[こちら]を見て(https://stackoverflow.com/questions/45343459/class-not-found -exception-using-custom-cordova-plugin)を使用します。私はあなたが '' –

答えて

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]); 
}; 
+0

の宣言にいくつかの道を見逃していると思います。コードページのリファレンスページhttps://cordova.apache.org/docs/en/latest/plugin_ref/spec.html#config-fileにあるplugin.xmlの機能のセクションに関するドキュメントは見つかりませんでした – Wizardskills