Android java.lang.UnsatisfiedLinkError - nativeLibraryDirectories(Eclipse)

时间:2014-08-12 17:50:08

标签: java android eclipse android-ndk

我正在使用Eclipse并使用NDK版本" r9d"。尝试加载库时,我一直收到不满意的链接错误。

我花了几个小时试图在这里找到答案,例如thisthis,但在尝试了列出的所有解决方案后,我仍然收到相同的错误。

Application.mk

NDK_TOOLCHAIN_VERSION=4.8
APP_CPPFLAGS    := -frtti -fexceptions -std=c++11
APP_STL          = gnustl_static
# armeabi armeabi-v7a mips
APP_ABI         := x86
APP_PLATFORM    := android-16

Android.mk

JNI_PATH := $(call my-dir)
LOCAL_PATH := $(JNI_PATH)

#include $(call all-subdir-makefiles)
include $(JNI_PATH)/C3Core/Android.mk
include $(JNI_PATH)/boost/Android.mk

LOCAL_PATH := $(JNI_PATH)
OPENCV_CAMERA_MODULES:=off
OPENCV_INSTALL_MODULES:=on
OPENCV_LIB_TYPE:=SHARED
include $(JNI_PATH)/OpenCV/sdk/native/jni/OpenCV.mk

LOCAL_MODULE    := Visualizer
LOCAL_SRC_FILES += Visualizer.cpp
LOCAL_C_INCLUDES += $(LOCAL_PATH)
LOCAL_LDLIBS     += -llog -ldl -landroid -ljnigraphics  
LOCAL_CPP_FEATURES += exceptions
LOCAL_STATIC_LIBRARIES += boost_system boost_thread boost_filesystem c3core opencv
include $(BUILD_SHARED_LIBRARY)

Visualizer.java

public class Visualizer {

    public native Bitmap generate(AssetManager mgr, String specifier);

    public native int getSurfaceIndex(int x, int y);

     static {
        try {
            System.loadLibrary("opencv_java");
            System.loadLibrary("Visualizer");
        } catch (UnsatisfiedLinkError e) {
            Log.v("ERROR", "" + e);
        }
    }
}

Android Manifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.iko"
    android:versionCode="1"
    android:versionName="1.0" >

日志

08-12 15:10:22.849: V/ERROR(30905): java.lang.UnsatisfiedLinkError: Couldn't load opencv_java from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.iko-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.iko-1, /vendor/lib, /system/lib]]]: findLibrary returned null

现在我知道这意味着它无法找到库,但我不知道如何解决这个问题。 该库位于我的项目中 libs / x86 / ,eclipses项目资源管理器中的完整文件名为 libopencv_java.so - [x86 / le]

如果需要更多细节,请随时提出任何帮助。

修改

我也试过这个

static {
    try {
        System.load("/data/data/com.example.iko/lib/x86/libopencv_java.so");
        System.load("/data/data/com.example.iko/lib/x86/libVisualizer.so");
    } catch (UnsatisfiedLinkError e) {
        Log.v("ERROR", "" + e);
    }
}

我收到此错误 -

08-12 14:55:16.259: V/ERROR(29582): java.lang.UnsatisfiedLinkError: dlopen failed: library "/data/data/com.example.iko/lib/x86/libopencv_java.so" not found

1 个答案:

答案 0 :(得分:0)

请改为尝试:

static {
    try {
        System.loadLibrary("opencv_java");
        System.loadLibrary("Visualizer");
    } catch (UnsatisfiedLinkError e) {
        Log.v("ERROR", "" + e);
    }
}

您不应该将libs / abi部分包含在传递给loadLibrary的库名中。在安装APK时,实际上只在电话上提取了正确的abi子目录,并且loadLibrary函数搜索了本机库被提取到的目录。 (此外,在为搜索匹配的文件时,您为loadLibrary提供的名称前缀为'lib',后缀为'.so' - 因此您只应传递库基本名称而不是其他内容。)