参照实例: Android.mk: LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE :=hello-world LOCAL_SRC_FILES :=hello-world.c LOCAL_SHARED_LIBRARIES := hello-jni LOCAL_LDLIBS += -llog include $(BUILD_SHARED_LIBRARY) 相对应的c代码: #include "string.h" #include "jni.h" #include "dlfcn.h" #include <fcntl.h> void * filehandle = NULL; jint (*getResult)(JNIEnv *, jobject, jint, jint) =NULL; jint JNICALL Java_com_example_hellojni_HelloAct_getInt(JNIEnv * env, jobject thiz) { jint result = 0; filehandle = dlopen("libhello-jni.so", RTLD_LAZY); if (filehandle) { getResult = (jint (*)(JNIEnv *, jobject, jint, jint)) dlsym(filehandle, "Java_com_example_hellojni_HelloJni_add"); if (getResult) result = getResult(env, thiz, 3, 10); dlclose(filehandle); filehandle = NULL; } return result + 1; } |
|