分享

android下JNI中C调用第三方SO 重新打包生成自己的SO

 昵称597197 2015-08-27
参照实例:
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;
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多