android下JNI中C调用第三方SO 重新打包生成自己的SO
参照实例:Android.mk:LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE :=hello-worldLOCAL_SRC_FILES :=hello-world.cLOCAL_SHARED_LIBRARIES := hello-jniLOCAL_LDLIBS += -lloginclude $(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;}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。