Class Not Found Exception using custom cordova plugin

后端 未结 4 1748
旧巷少年郎
旧巷少年郎 2021-01-27 11:45

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

相关标签:
4条回答
  • 2021-01-27 12:23

    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.

    0 讨论(0)
  • 2021-01-27 12:43

    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.

    0 讨论(0)
  • 2021-01-27 12:43

    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.

    0 讨论(0)
  • 2021-01-27 12:49

    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" /> 
    
    0 讨论(0)
提交回复
热议问题