3

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

Gabriel
  • 139
  • 2
  • 11
  • make sure it is set in android build path – Mohammed Imran N Jun 26 '14 at 14:31
  • Which file contains the android build path please? – Gabriel Jun 27 '14 at 07:18
  • 1
    In fact, all was good, the only problem was that IndexSearcher implements java.rmi and Android doesn't have this package. To resolve this problem, we must do two things: 1. Delete "extends java.rmi.Remote" from the Class "org.apache.lucene.search.Searchable" 2. Delete class "org.apache.lucene.search.RemoteSearchable" http://stackoverflow.com/questions/7821103/lucene-in-android – Gabriel Jun 27 '14 at 13:26

3 Answers3

1

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.

Pang
  • 9,564
  • 146
  • 81
  • 122
Hardik Thakkar
  • 394
  • 5
  • 17
0

Look at this answer for the same question. Just put you library in a top level directory at the individual plugin. It works for me.

Community
  • 1
  • 1
Nisazh
  • 306
  • 1
  • 7
0

If you need to reference a library existing on the device at certain namespace you can use "framework" tag

<!-- Depend on latest version of GCM from play services -->
<framework src="com.google.android.gms:play-services-gcm:+" />
<!-- Depend on v21 of appcompat-v7 support library -->
<framework src="com.android.support:appcompat-v7:21+" />
<!-- Depend on library project included in plugin -->
<framework src="relative/path/FeedbackLib" custom="true" />

https://cordova.apache.org/docs/en/latest/plugin_ref/spec.html#framework

Guilherme Ferreira
  • 2,209
  • 21
  • 23