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

在开发一个使用自定义API通过USB访问打印机的应用时,遇到了Cordova自定义插件的问题。插件安装和JavaScript代码运行正常,但在运行时出现错误,Android Monitor显示ClassNotFoundException。问题可能出在jar文件路径配置或Android平台文件夹的类路径匹配上。解决方案包括检查jar文件路径和逐个声明Android源文件。
摘要由CSDN通过智能技术生成

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:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值