打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
android下JNI中C调用第三方SO 重新打包生成自己的SO
参照实例:
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;
}

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
JNI编程进阶
Android Studio JNI开发入门教程
JNI技术与Android应用(0)
Android JNI开发提高篇
NDK 之 JNI数据传输
JNI_Android项目中调用.so动态库
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服