1.问题描述:
在android apk中需要使用dlopen打开/system/vendor/lib64/egl/libGLES_mali.so失败
2.原因:
android安全机制导致,mali库在system目录下,APK无权限执行
3.解决:
编写public.libraries.txt,写两行,一行内容是libGLES_mali.so,另一行是回车换行。
4.测试代码:
#include <jni.h>
#include <string>
#include <dlfcn.h>
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_testmali_MainActivity_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
std::string hello = "Hello from C++";
void *handle = dlopen("/system/vendor/lib64/egl/libGLES_mali.so", RTLD_NOW);
if (!handle) {
hello = "Open Failed!";
}
else {
hello = "Open Success!";
dlclose(handle);
}
return env->NewStringUTF(hello.c_str());
}