2017-09-20 6 views
0

Ich versuche ein Plugin für Cordova zu schreiben und ich bekomme diese Fehlermeldung, wenn ich versuche und auf einem Android-Gerät interagieren.Cordova Plugin - Klasse kann nicht gefunden werden

Hier ist mein Java-Code, den ich vereinfacht habe.

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 
} 

Hier ist meine Javascript-Schnittstelle Wrapper

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

Und hier ist mein 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> 

Hat jemand eine Ahnung, warum sollte ich eine Klasse bekommen nicht Fehler entdeckt? Ich habe versucht, einige der Werte in der plugin.xml-Datei zu ändern, aber nichts scheint zu funktionieren.

+0

einen Blick [hier] (https://stackoverflow.com/questions/45343459/class-not-found -exception-using-custom-cordova-plugin). Ich denke, dass Sie einige Pfade in der Erklärung der '' –

Antwort

0

Das Problem besteht darin, wie Sie Ihr Plugin in plugin.xml deklarieren und dann darauf in der Javascript-Schnittstelle verweisen.

ändern plugin.xml zu:

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

Und Javascript-Schnittstelle:

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

Brilliant vermissen, danke, es funktioniert jetzt! Ich konnte keine Dokumentation über den Funktionsbereich der plugin.xml auf der Cordova-Referenzseite https://cordova.apache.org/docs/en/latest/plugin_ref/spec.html#config-file finden – Wizardskills

Verwandte Themen