JNI的使用

来源:互联网 发布:mac沙盒机制 编辑:程序博客网 时间:2024/06/01 19:05

JNI
1. create java file which call c method
2. generate *.h file from java class file
javap -cp . HelloJNI
3. create so file with gcc/g++ compiler
4. run java with -Djava.library.path=path_to_lib
The native programs:
3.1 Receive the arguments in JNI type (passed over by the Java program).
3.2 For reference JNI type, convert or copy the arguments to local native types, e.g., jstring to a C-string, jintArray to C’s int[], and so on. Primitive JNI types such as jint and jdouble do not need conversion and can be operated directly.
3.3 Perform its operations, in local native type.
3.4 Create the returned object in JNI type, and copy the result into the returned object.
3.5 Return.

jni example
https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html
jni spec
http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/jniTOC.html
jni tips
developer.android.com/training/articles/perf-jni.html

0 0
原创粉丝点击