简体   繁体   中英

Add JavaML library to Android Project

I'm new to Android, even new to Java. I'm also new to SO, so I can't post more than 2 links, sorry :/. I need to use a LibSVM object contained in JavaML library (java-ml.sourceforge.net), and every time I want to use it, I import libsvm.LibSVM (no failure there), and use LibSVM test = new LibSVM(); . At this moment my app crashes with a NoClassDefFoudError :

05-31 16:25:42.692 1353-1353/myapp E/dalvikvm: Could not find class 'libsvm.LibSVM$1', referenced from method libsvm.LibSVM.<clinit>
05-31 16:25:42.692 1353-1353/myapp E/dalvikvm: Could not find class 'libsvm.svm_parameter', referenced from method libsvm.LibSVM.<init>
05-31 16:25:42.692 1353-1353/myapp E/dalvikvm: Could not find class 'libsvm.svm_node[]', referenced from method libsvm.LibSVM.convert
05-31 16:25:42.702 1353-1353/myapp E/dalvikvm: Could not find class 'libsvm.svm_problem', referenced from method libsvm.LibSVM.transformDataset
05-31 16:25:42.732 1353-1353/myapp E/InputEventReceiver: Exception dispatching input event.
05-31 16:25:42.732 1353-1353/myapp E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
05-31 16:25:42.747 1353-1353/myapp E/MessageQueue-JNI: java.lang.NoClassDefFoundError: libsvm.LibSVM$1
                                                                             at libsvm.LibSVM.<clinit>(LibSVM.java:28)
                                                                             at myapp.TouchDisplayView.onTouchEvent(TouchDisplayView.java:159)
                                                                             ... stacktrace

I read How do I add a library project to Android Studio? , How to add classpath in an Android Studio project , but it didn't work (for the latter, I am stuck at step 5 because Android Studio does not recognizes my .jar when creating a new module).

I added compile files("libs/javaml/javaml-0.1.7.jar") in my build.gradle , also all the files from javaml/lib/ "for more convenience", as the doc says (java-ml.sourceforge.net/content/installing-library). Then Build clean, and rebuild. Still a nope.

What is weird to me is that Android Studio has no trouble finding the classes, yet for some reason my phone begs to differ.

My tree so far: i.stack.imgur.com/P2DY4.png

I would be extremely glad if someone could provide me a indication of how to proceed. Thanks in advance!

Ok, so I don't really know what happened, but I re-compiled everything, uninstalled the app on my phone, built everything again and now it works. No idea why, because I have been struggling on the issue for the whole afternoon.

Sorry for the problem-not-problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM