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 challe
This is the most important part of your stacktrace:
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.duplou.cordova.plugin.customprinter.CustomPrinter"
Your Cordova configuration references the CustomPrinter
plugin. When Javascript triggers loading it, the Java class cannot be found and thus your application crashes.
You need to ensure that the Java class is present in your application package.
I have this error and solved it by change android.json file in \platforms\android\android.json
You must change value of res/xml/config.xml to your package of custom Plugin.
The reason is package of your custom plugin and value of above in not same.
In my case I had multiple .java files referenced. When I changed the ordering of how it is referenced in plugin.xml, it fixed the problem. Seems like the last .java file is dependent on the second last one.
Before:
<!--libs-->
<source-file src="libs/sample-release.aar" target-dir="libs/" />
<source-file src="src/android/Licence.java" target-dir="src/android/" />
<source-file src="src/android/Deserializer.java" target-dir="src/android/" />
After:
<!--libs-->
<source-file src="libs/sample-release.aar" target-dir="libs/" />
<source-file src="src/android/Deserializer.java" target-dir="src/android/" />
<source-file src="src/android/Licence.java" target-dir="src/android/" />
So just by switching the ordering, the ClassNotFoundException was resolved.
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:
<source-file src="src/android/src/net/mydomain/myplugin/MyClass.java" target-dir="src/mydomain/myplugin" />