我已经预编译了共享库 (.so),名为 libxxx.so.3.3。不知道为什么编译后的名字是“libxxx.so.3.3”。我想通过 JNI 在我的 Android 应用程序中使用它。为此,我创建了 ndk 模块 xxx_jni:
安卓.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := xxx
LOCAL_SRC_FILES := xxx.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := xxx_jni
LOCAL_SRC_FILES := xxx_wrapper.c
LOCAL_SHARED_LIBRARIES := xxx
LOCAL_C_INCLUDES := /softdev/xxx/host/include/
include $(BUILD_SHARED_LIBRARY)
我不得不将“ .so.3.3”重命名为“ .so”,因为 ndk-build 无法编译 libxxx_jni.so:
Android NDK: ERROR:/Users/user/Documents/dev/src/xxx_jni/jni/Android.xxx: LOCAL_SRC_FILES should point to a file ending with ".so"
Android NDK: The following file is unsupported: libxxx.so.3.3
我的包装类(用于 JNI):
#include "xxx_wrapper.h"
#include <xxx-c/Index.h> // include "xxx" library header
#ifndef _Included_name_antonsmirnov_android_xxx_wrapper
#define _Included_name_antonsmirnov_android_xxx_wrapper
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: name_antonsmirnov_android_xxx_wrapper
* Method: exec_test
* Signature: (Ljava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_name_antonsmirnov_android_xxx_1wrapper_exec_1test(JNIEnv *, jobject, jstring)
{
// using method from "xxx" library
xxx_method();
return 7;
}
因此,在 ndk 编译(ndk-build)之后,我在“libs/armeabi”文件夹中有 2 个剥离的文件:libxxx.so 和 libxxx_jni.so。
然后我尝试在包装类的运行时加载库:
public class xxx_wrapper {
static {
System.loadLibrary("xxx");
System.loadLibrary("xxx_jni"); // error here!
}
错误:
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1891]: 167 could not load needed library 'libxxx.so.3.3' for 'libxxx_jni.so' (load_library[1093]: Library 'libxxx.so.3.3' not found)
所以我陷入了我错过的事情。我试图离开“.so.3.3”扩展名和符号链接“.so”->“.so.3.3”,但结果相同。据我了解,问题是 xxx_wrapper lib 仍然希望加载“.so.3.3”库,但它是“.so”。