简体   繁体   中英

Android java.lang.UnsatisfiedLinkError - nativeLibraryDirectories (Eclipse)

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

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

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" >

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] .

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

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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM