Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova: add library in a plugin

I've created a cordova plugin like this tree:

LucenePlugin
   src
        android
             libs
                  lucene-analyzers-2.4.1.jar
                  lucene-core-2.4.1.jar
                  lucene-snowball-2.4.1.jar
             LucenePlugin.java
   www
        lucene.js
   plugin.xml

In the plugin.xml, I added the .jar like this

 <platform name="android">
    <config-file target="res/xml/config.xml" parent="/*">
        <feature name="org.apache.cordova.LuceneLibs"> 
            <param name="android-package" value="org.apache.cordova.LuceneLibs"/>
        </feature>
    </config-file>
    <source-file src="src/android/lucene-analyzers-2.4.1.jar" target-dir="libs" framework="true"/>
    <source-file src="src/android/lucene-core-2.4.1.jar" target-dir="libs" framework="true"/>
    <source-file src="src/android/lucene-snowball-2.4.1.jar" target-dir="libs" framework="true"/>       
</platform>

When I add the plugin into cordova project, the libs seems to be at the good place:

platforms\android\libs\lucene-analyzers-2.4.1.jar etc...

Unfortunately, when I run the project, I have this error

W/System.err(12492): java.lang.NoClassDefFoundError:
org.apache.lucene.search.IndexSearcher
W/System.err(12492):    at   
org.apache.cordova.Lucene.LucenePlugin.execute(LucenePlugin.java:27)
W/System.err(12492):    at   
org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:65)
W/System.err(12492):    at 
org.apache.cordova.PluginManager.execHelper(PluginManager.java:242)

Do you know what I forgot?

Thanks

like image 364
Gabriel Avatar asked Feb 01 '26 17:02

Gabriel


1 Answers

I am having the same issue. The jar file landed at correct place. But as this newly added jar file is not added to build path, it is obvious that you will get error for class not found for all those classes in your jar file. If you are installing this plugin in your local project, simply add this jar file to your build path. It will solve your problem. But if you want to use this plugin in cloud platform like phonegap build, there can be a trouble.. I am searching for a way around for that.

like image 107
Hardik Thakkar Avatar answered Feb 03 '26 07:02

Hardik Thakkar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!