1.在工程源码目录下 src/com 新建 testjni目录
创建java类文件 TestJni.java 添加如下代码
package com.testjni;
public class TestJni {
public native void TestJniFunc();
}
2.生成jni头文件方法
进入 bin/class目录下 运行
javah -classpath . -jni com.cimovjni.TestJni
成功后会在当前目录下生成com_cimovjni_TestJni.h文件
3.根据头文件创建.cpp源文件 并添加相应的代码 如下:
#include < utils/Log.h >
#include < android/log.h >
#include "com_testjni_TestJni.h"
/*
* Class: com_testjni_TestJni
* Method: TestJniFunc
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_testjni_TestJni_TestJniFunc
(JNIEnv *, jobject)
{
ALOGD("damon === > jni test n");
}
4.编译jni 动态库 添加对应的Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_PREBUILT_LIBS :=
include $(BUILD_MULTI_PREBUILT)
include $(CLEAR_VARS)
LOCAL_SRC_FILES :=
com_testjni_TestKtvJni.cpp
LOCAL_C_INCLUDES :=
$(TOP)/hardware/libhardware/include/
$(TOP)/frameworks/base/include/
LOCAL_SHARED_LIBRARIES :=
libcutils libutils
LOCAL_MODULE := libTestJni
LOCAL_MODULE_TAGS := optional
include $(BUILD_SHARED_LIBRARY)