侧边栏壁纸
博主头像
银河驿站博主等级

行动起来,活在当下

  • 累计撰写 85 篇文章
  • 累计创建 17 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

android获取动态库路径

Administrator
2023-10-17 / 0 评论 / 0 点赞 / 115 阅读 / 1562 字

android8以下通过JNI获取

#include <jni.h>
#include <dlfcn.h>

JNIEXPORT jstring JNICALL
Java_com_example_app_MainActivity_getLibraryPath(JNIEnv *env, jobject thiz) {
    void* handle = dlopen(NULL, RTLD_LAZY);
    if (handle != NULL) {
        char *path = NULL;
        Dl_info info;
        int ret = dladdr(handle, &info);
        if (ret != 0) {
            path = (char*)info.dli_fname;
            return (*env)->NewStringUTF(env, path);
        }
        dlclose(handle);
    }
    return NULL;
}

android8以上获取方法

1.使用ApplicationInfo.nativeLibraryDir属性

String libraryPath = getApplicationContext().getApplicationInfo().nativeLibraryDir;

这个属性会返回应用的本地库(动态库)的目录路径

2.android.content.Context.getPackageCodePath()方法

String apkPath = getApplicationContext().getPackageCodePath();

这个方法会返回应用 APK 文件的路径,可以从中提取出动态库的路径。

0

评论区