1 Star 0 Fork 0

arte/jni_study

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
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

空文件

简介

share how to study jni 展开 收起
C
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/arte/jni_study.git
git@gitee.com:arte/jni_study.git
arte
jni_study
jni_study
master

搜索帮助

D1d26d21 1850385 D1bef801 1850385