cordova打印机插件,找不到类使用自定义cordova插件的异常

I'm developing a printing app that uses a custom API to access the printer via USB, so I needed a custom Cordova plugin. I started developing it, it has been a very good challenge but also very frustrating at the moment because I can't figure out why my plugin can't be used correctly.

The thing is:

1.- The plugin installs correctly and lets me build the application

2.- The Javascript code runs correctly

3.- I get a runtime error that doesn't crash the app. It seems like the Java code is skipped. And I noticed there was an error in the Android Monitor.

W/System.err: java.lang.ClassNotFoundException: com.duplou.cordova.plugin.customprinter.CustomPrinter

W/System.err: at java.lang.Class.classForName(Native Method)

W/System.err: at java.lang.Class.forName(Class.java:324)

W/System.err: at java.lang.Class.forName(Class.java:285)

W/System.err: at org.apache.cordova.PluginManager.instantiatePlugin(PluginManager.java:489)

W/System.err: at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:169)

W/System.err: at org.apache.cordova.PluginManager.exec(PluginManager.java:122)

W/System.err: at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:57)

W/System.err: at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41)

W/System.err: at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)

W/System.err: at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:53)

W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)

W/System.err: at android.os.Looper.loop(Looper.java:148)

W/System.err: at android.os.HandlerThread.run(HandlerThread.java:61)

W/System.err: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.duplou.cordova.plugin.customprinter.CustomPrinter" on path: DexPathList[[zip file "/data/app/1/lib/1/base.apk!/lib/x86, /vendor/lib, /system/lib]]

W/System.err: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)

W/System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:511)

W/System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:469)

W/System.err: ... 13 more

W/System.err: Suppressed: java.lang.ClassNotFoundException: com.duplou.cordova.plugin.customprinter.CustomPrinter

W/System.err: at java.lang.Class.classForName(Native Method)

W/System.err: at java.lang.BootClassLoader.findClass(ClassLoader.java:781)

W/System.err: at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)

W/System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:504)

W/System.err: ... 14 more

W/System.err: Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

I/System.out: Error adding plugin com.duplou.cordova.plugin.customprinter.CustomPrinter.

W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CordovaPlugin.privateInitialize(java.lang.String, org.apache.cordova.CordovaInterface, org.apache.cordova.CordovaWebView, org.apache.cordova.CordovaPreferences)' on a null object reference

W/System.err: at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:171)

W/System.err: at org.apache.cordova.PluginManager.exec(PluginManager.java:122)

W/System.err: at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:57)

W/System.err: at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41)

W/System.err: at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)

W/System.err: at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:53)

W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)

W/System.err: at android.os.Looper.loop(Looper.java:148)

W/System.err: at android.os.HandlerThread.run(HandlerThread.java:61)

D/SystemWebChromeClient: file:///android_asset/www/plugins/cordova-custom-printer-plugin/www/custom-printer.js: Line 11 : Se terminó la ejecución

I/chromium: [INFO:CONSOLE(11)] "Se terminó la ejecución", source: file:///android_asset/www/plugins/cordova-custom-printer-plugin/www/custom-printer.js (11)

D/CordovaWebViewImpl: onPageFinished(file:///android_asset/www/index.html)

W/PluginManager: THREAD WARNING: exec() call to Sim.getSimInfo blocked the main thread for 53ms. Plugin should use CordovaInterface.getThreadPool().

D/SystemWebChromeClient: file:///android_asset/www/build/main.js: Line 1436 : ERROR

I/chromium: [INFO:CONSOLE(1436)] "ERROR", source: file:///android_asset/www/build/main.js (1436)

W/BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 12139

D/EGL_emulation: eglMakeCurrent: 0xae414a40: ver 2 0 (tinfo 0xa14bfbe0)

Here's my ionic info output

global packages:

@ionic/cli-utils : 1.5.0

Cordova CLI : 7.0.1

Ionic CLI : 3.5.0

local packages:

@ionic/app-scripts : 1.3.7

@ionic/cli-plugin-cordova : 1.4.1

@ionic/cli-plugin-ionic-angular : 1.3.2

Cordova Platforms : android 6.2.3

Ionic Framework : ionic-angular 3.2.1

System:

Node : v6.10.3

OS : macOS Sierra

Xcode : Xcode 8.3.2 Build version 8E2002

ios-deploy : not installed

ios-sim : not installed

npm : 3.10.10

解决方案

I see that you are pointing to a jar file in your config.xml. If you really want to keep using this jar file make sure that the path is correctly mapped in android platform folders and it matches the classpath.

If you want to do a simple test, you should declare your android source files one by one. So after the node config-file you should add several nodes like this one:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果你的 Cordova定义件暴露的方法无法被调用,可能是因为你在件代码中没有正确地暴露它们。以下是一些可能的原因和解决方案: 1. 检查定义是否正确 在你的定义中,确保你已经正确地定义了你要暴露的方法。例如: ```xml <js-module src="www/MyPlugin.js" name="MyPlugin"> <clobbers target="window.MyPlugin" /> </js-module> ``` 在这个例子中,件暴露了一个名为 `MyPlugin` 的 JavaScript 对象,并将它附加到全局 `window` 对象上。你需要确保你的 JavaScript 代码正确地定义了这个对象,并将要暴露的方法添加到这个对象上。 2. 检查方法名称是否正确 确保你在调用件方法时使用了正确的名称。例如,如果你定义了一个名为 `myMethod` 的方法,那么在调用它时应该使用这个名称: ```javascript window.MyPlugin.myMethod(args, successCallback, errorCallback); ``` 3. 检查方法参数是否正确 确保你在调用件方法时使用了正确的参数。如果你的方法需要传递参数,那么你需要在调用方法时提供这些参数。例如: ```javascript window.MyPlugin.myMethod("arg1", "arg2", successCallback, errorCallback); ``` 4. 检查 webview 是否已经加载件 确保你的 Cordova webview 已经正确地加载了你的件。你可以在 webview 加载完成后检查 `window.MyPlugin` 是否存在。 如果以上这些方法都没有解决你的问题,那么你可以尝试在调试模式下运行你的应用程序,并使用开发者工具来查看是否有任何错误消息或异常

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值