java 生成jni,使用'javah'与JNI生成头文件

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.

$ 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.

解决方案

Solution: Generating header file with JNI using 'javah'

***I am using Window 10 and Android Studio 2.1.2.***

Suppose APP (JNIP my app Name) location is

E:\test\JNIP and you wrote native methods in JniExample.java file

JDK Location is

C:\Program Files\Java\jdk1.8.0_51\bin>

JNI Folder Location is

E:\test\JNIP\app\src\main\JNI (where, you want to create header file)

Class Location is

E:\test\JNIP\app\build\intermediates\classes\debug\com\example\mpankaj\jnip\JniExample.java

Android.jar location is

C:/Users/mpankaj/AppData/Local/Android/Sdk/platforms/android-23/android.jar

First Build your project before running below command

Write Command on coommand prompt/Terminal for .h file creation

javah -d (JNI Folder Location) -classpath (JAR Locaion);(class Location)

Example Command using above details for Command

C:/Program Files/Java/jdk1.8.0_51/bin>javah -d E:/test/JNIP/app/src/main/JNI -classpath C:/Users/mpankaj/AppData/Local/Android/Sdk/platforms/android-23/android.jar;E:\test\JNIP\app\build\intermediates\classes\debug com.example.mpankaj.jnip.JniExample

After this you will get .h file like this com_example_mpankaj_jnip_JniExample.h

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值