# jni_study **Repository Path**: arte/jni_study ## Basic Information - **Project Name**: jni_study - **Description**: share how to study jni - **Primary Language**: C - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-12-27 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README step 1: add source file step 2: add makefile and build shared object err: ➜ ./main ./main: error while loading shared libraries: libmyjni.so: cannot open shared object file: No such file or directory fix: export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH step 3: how to use libmyjni.so in java method a.step 1 load library b.step 2 add native method to call c method err: javac JniTest.java java JniTest hello jni Exception in thread "main" java.lang.UnsatisfiedLinkError: JniTest.sum_c(II)I at JniTest.sum_c(Native Method) at JniTest.main(JniTest.java:8) why? no map in java native method and c shared object. fix: new c file to map java native method and c function. we often call this operation JNI-java native interface err: native_jni.c:1:17: fatal error: jni.h: 没有那个文件或目录 fix: add -I arg gcc -I/usr/lib/jvm/java-8-openjdk-amd64/include/ step 4: static register jni method a. javac JniTest.java b. javah -jni JniTest //auto create JniTest.h c. include JniTest.h in native_jni.c step 5: just only one so lib step 6: add android project step 7: use jni lib in android project step 8: support ndk build for android project