0

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
Community
  • 1
  • 1
Jawascript
  • 683
  • 1
  • 7
  • 23
  • Use ADB with the run-as tool or an (implicitly rooted) compatible-ABI emulator to examine the app installation and see if the library in question is actually present. If it is not, open the apk as a zip file and see if it made it into that. – Chris Stratton Aug 12 '14 at 21:18

1 Answers1

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

mstorsjo
  • 12,983
  • 2
  • 39
  • 62
  • Please see the edit, I had a typo in there, but I have tried this. – Jawascript Aug 12 '14 at 20:17
  • Have you tried skipping the System.loadLibrary("opencv_java")? Since the Android.mk entry for Visualizer only mentions static libs, not dynamic (only LOCAL_STATIC_LIBRARIES, no LOCAL_SHARED_LIBRARIES), I would assume that libVisualizer.so doesn't depend on libopencv_java.so, but all of it is linked in statically already. Thus System.loadLibrary("Visualizer") should be enough. If not, please post the output of "unzip -l yourapp.apk | grep libs". – mstorsjo Aug 12 '14 at 20:29
  • Also, just to be really sure - you're sure your device is an x86 device, not an arm one? – mstorsjo Aug 12 '14 at 20:30
  • Checked if only Visualizer would work, it would not, it was still not found. I think you are on to something with the x86 device though. I just had a lightbulb because this code was sent from another dev who is using an emulator. I am using a nexus 7. Feeling kind of silly right now. Lets see what happens – Jawascript Aug 12 '14 at 20:39
  • 1
    The nexus 7 is arm, not x86, so remove the APP_ABI line from Applications.mk (arm is default), or add "armeabi" (or armeabi-v7a) there as well, or change it into "all", to build a larger binary supporting all official ABIs. – mstorsjo Aug 13 '14 at 05:49
  • You were right with your second guess as I knew almost immediatly. As soon as you said "are you sure its x86?" I knew where everything had gone wrong. It works perfectly now. Thank you for your help – Jawascript Aug 13 '14 at 18:27