Generating header file with JNI using 'javah'

user3019612 picture user3019612 · Feb 9, 2014 · Viewed 16.4k times · Source

I'm trying to use JNI for an Android application using the OpenCV4Android library. I can generate a header file without using the opencv library, but I get an error whenever the class imports anything. I assume it needs to link to the library, but I'm not sure how to do that? I'm using cygwin on a Windows 8.1 64 bit machine.

original output:

$ javah -jni -classpath ./bin/classes -d jni/ com.example.icam.nativeRDE  
Error: Class org.opencv.core.Mat could not be found.

After following advice from: Android, generate jni Header Files with javah , show error that can't find org.opencv.core.Mat, I get the following output:

$ javah -classpath /cygdrive/c/Users/Majid/Documents/OpenCV4Android/OpenCVLib2.4.8/bin/classes/org/opencv/;/cygdrive/c/Users/Majid/Documents/OpenCV4Android/iCam/bin/classes/com/example/icam/ -jni -d jni/ com.example.icam.nativeRDE
Error: no classes specified
-bash: /cygdrive/c/Users/Majid/Documents/OpenCV4Android/iCam/bin/classes/com/example/icam/: is a directory

I've tried:

  • removing '/' after icam
  • adding nativeRDE after 'icam/'
  • adding nativeRDE.class after 'icam/'

Thanks for any help.

Answer

ylmzekrm1223 picture ylmzekrm1223 · Aug 14, 2014

Javah takes a fully qualified class name, and classpath. Class name must be with full package name.
Ex:fullPackageName.className

Class path is your src folder not bin folder Your classpath must be c\Users\Majid\Documents\OpenCV4Android\iCam\src

Javah -jni -classpath C:\ProjectName\src com.abc.YourClassName