【系统移植】JNI

jni代码

java调用jni的接口:

1, 调用动态库

static{
 
  System.loadLibrary("led_jni");  // system/lib/libled_jni.so
 }

2, 调用驱动方法名:
    public native int openDev();
  
3, 直接去调用,不需要去实现openDev()

openDev();
 public native int openDev();
 public native int DevOn();
 public native int DevOff();
 public native int closeDev();

jni的接口代码: jni代码(*.cpp)==>libled_jni.so

参考模板:Native.cpp development\samples\simplejni\Jni 2599 2011-5-17

, JNI_OnLoad()   ;
 a, 获取jni的版本,和dvm的运行环境对象 env (提供操作jni的方法)
  原型
    错误
   
 b, 构建映射表, 注册给dvm
  表示映射表]));

Android.mk

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= led_jni.cpp
LOCAL_MODULE :=libled_jni

#指定连接动态库< 类似于gcc  -lxx
LOCAL_SHARED_LIBRARIES := \
        libcutils
#指定头文件路径, 类似于gcc -Ixxx
LOCAL_C_INCLUDES += \
        $(JNI_H_INCLUDE)
#编译成so,需要一个标志
LOCAL_PRELINK_MODULE := false
include $(BUILD_SHARED_LIBRARY)

编译:

..
target SharedLib: libled_jni (out/target/product/fs100/obj/SHARED_LIBRARIES/libled_jni_intermediates/LINKED/libled_jni.so)
target Non-prelinked: libled_jni (out/target/product/fs100/symbols/system/lib/libled_jni.so)
target Strip: libled_jni (out/target/product/fs100/obj/lib/libled_jni.so)
Install: out/target/product/fs100/system/lib/libled_jni.so
make:离开目录“/home/ldswfun/src_s5pc/eclair_2.1_farsight”

运行:

apk===> /system/app
so ==> /syste/lib/
cp -raf out/target/product/fs100/system/lib/libled_jni.so   /opt/myrootfs/system/lib

@成鹏致远

(blogs:http://lcw.cnblogs.com)

(emailwwwlllll@126.com)

上一篇:xxx.java: Recompile with -Xlint:deprecation for details


下一篇:tp5增删改查基本操作