Android . lang。如果nativeLibraryDirectories(Eclipse)

时间:2023-01-21 15:42:34

I am working with Eclipse and using the NDK version "r9d". I keep getting an unsatisfied link error when trying to load a library.

我正在使用Eclipse,并使用NDK版本的“r9d”。在尝试加载一个库时,我总是得到一个不满意的链接错误。

I've spent a couple hours trying to find answers on here like this or this, but after trying all the solutions listed I'm still receiving the same error.

我花了几个小时试图在这里找到答案,但在尝试了所有的解决方案之后,我仍然会收到同样的错误。

Application.mk

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

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

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

Android Manifest.xml

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

Log

日志

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

Now I know this means it can't find the library, but I have no idea how to fix this. The library is located inside my project at libs/x86/ and the full file name in eclipses project explorer is libopencv_java.so - [x86/le].

现在我知道这意味着它找不到图书馆,但我不知道如何解决这个问题。该库位于我的项目中,在libs/x86/和eclipse项目资源管理器中的完整文件名称是libopencv_java。所以——[x86 / le]。

Any help is appreciated, if any more details are needed feel free to ask.

如果需要更多的细节,请随时提问。

EDIT

编辑

I've also tried this

我也试过这样

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);
    }
}

and I get this error -

我得到这个误差。

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 个解决方案

#1


0  

Try this instead:

试试这个:

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

You're not supposed to include the libs/abi part in the library name passed to loadLibrary. Upon installation of the APK, only the right abi subdirectory is actually extracted on the phone, and the directory the native libs are extracted into is searched by the loadLibrary function. (Also, the names you give to loadLibrary are prefixed with 'lib' and suffixed with '.so' when searching for matching files - thus you should only pass the library base name and nothing else.)

您不应该在传递给loadLibrary的库名称中包含libs/abi部分。在安装APK时,只有正确的abi子目录在电话中提取,并且将本机libs提取到的目录由loadLibrary函数进行搜索。(另外,您给loadLibrary的名称是前缀“lib”和后缀“。”因此,当搜索匹配的文件时,您应该只传递库的基本名称,而不是其他。

#1


0  

Try this instead:

试试这个:

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

You're not supposed to include the libs/abi part in the library name passed to loadLibrary. Upon installation of the APK, only the right abi subdirectory is actually extracted on the phone, and the directory the native libs are extracted into is searched by the loadLibrary function. (Also, the names you give to loadLibrary are prefixed with 'lib' and suffixed with '.so' when searching for matching files - thus you should only pass the library base name and nothing else.)

您不应该在传递给loadLibrary的库名称中包含libs/abi部分。在安装APK时,只有正确的abi子目录在电话中提取,并且将本机libs提取到的目录由loadLibrary函数进行搜索。(另外,您给loadLibrary的名称是前缀“lib”和后缀“。”因此,当搜索匹配的文件时,您应该只传递库的基本名称,而不是其他。