I just have a nasty problem with jni when I compile my own method in a java class with javah to create JNI header files.
If the class used a third-party package, for example: org.opencv.core.Mat, then javah will show an error that the org.opencv.core.Mat class cannot find.
Sample OpenCV code as shown below:
package org.opencv.samples.fd; import org.opencv.core.Mat; import org.opencv.core.MatOfRect; public class DetectionBasedTracker { public DetectionBasedTracker(String cascadeName, int minFaceSize) { mNativeObj = nativeCreateObject(cascadeName, minFaceSize); } public void start() { nativeStart(mNativeObj); } public void stop() { nativeStop(mNativeObj); } public void setMinFaceSize(int size) { nativeSetFaceSize(mNativeObj, size); } public void detect(Mat imageGray, MatOfRect faces) { nativeDetect(mNativeObj, imageGray.getNativeObjAddr(), faces.getNativeObjAddr()); } public void release() { nativeDestroyObject(mNativeObj); mNativeObj = 0; } private long mNativeObj = 0; private static native long nativeCreateObject(String cascadeName, int minFaceSize); private static native void nativeDestroyObject(long thiz); private static native void nativeStart(long thiz); private static native void nativeStop(long thiz); private static native void nativeSetFaceSize(long thiz, int size); private static native void nativeDetect(long thiz, long inputImage, long faces); }
I used the command first
javah -classpath bin/classes -bootclasspath (the directory of android.jar) -d jni (packageName + ClassName) , shows the error "can't find the org.opencv.core.Mat
Then I changed the command to
javah - classpath bin/classes - bootclasspath (the dir of android.jar) ; (the dir of the opencv lib jar) -d jni ..." ", this time it shows error
Exception
Exception in thread "main" java.lang.IllegalArgumentException: Not a valid class name: E:\Computer_Language\Java\soft_android\OpenCV-2.4.3-rc-android-sdk\OpenCV -2.4.3-rc-android-sdk\sdk\java\bin\opencv library - 2.4.3.jar at com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:177) at com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:68) at com.sun.tools.javah.JavahTask.run(JavahTask.java:509) at com.sun.tools.javah.JavahTask.run(JavahTask.java:335) at com.sun.tools.javah.Main.main(Main.java:46)
I think adding the opencv lib directory to -bootclasspath is useful and necessary. The error is that I just added two paths to -bootclasspath or is there something wrong with the format?
Really confused. Please help, thanks u!