Skip to content Skip to sidebar Skip to footer

Unsatisfied Link Error - Opencv For Android Non-native

A few days ago I asked about an UnsatisfiedLinkError from running non-native OpenCV code. I thought the problem was solved after reinstalling Eclipse and closing/reopening all the

Solution 1:

After a bunch of searching, I found this:

"3. If your application project doesn’t have a JNI part, just copy the corresponding OpenCV native libs from /sdk/native/libs/ to your project directory to folder libs/."

So that means copy the \armeabi, \armeabi-v7a, and \x86 folders.

"4. The last step of enabling OpenCV in your application is Java initialization code before call to OpenCV API. It can be done, for example, in the static section of the Activity class, which gets executed only once, before any instance of the class is created:

static {
    if (!OpenCVLoader.initDebug()) {
        // Handle initialization error
    }
}

Alternatively, you can put it inside the onCreate method:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_load_image);
    if (!OpenCVLoader.initDebug()) {
        // Handle initialization error
    }
    [...]
}

Now it works!

Solution 2:

you should use

if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_2, this, mOpenCVCallBack))
{
    Log.e("TEST", "Cannot connect to OpenCV Manager");
}

in OnCreate() And use

privateBaseLoaderCallbackmOpenCVCallBack=newBaseLoaderCallback(this) {
    @OverridepublicvoidonManagerConnected(int status) {
        switch (status) {
                case LoaderCallbackInterface.SUCCESS:
                {
                               MatImage= Highgui.imread("/image.jpg");
                               if (Image == null) {
                                   AlertDialogad=newAlertDialog.Builder(this).create(); 
                                   ad.setMessage("Fatal error: can't open /image.jpg!");  
                                }
                } break;
                default:
                {
                    super.onManagerConnected(status);
                } break;
            }
    }
    };

Solution 3:

In most situations, a line like this before calling openCV is enough: "System.loadLibrary(Core.NATIVE_LIBRARY_NAME);"

Solution 4:

I was adding opencv in my project in Android Studio. This error occurs when native files are not available at run time. So you have to copy native files at correct location.

First create the jniLibs at this location /app/src/main/ location and copy the all the folder with *.so files (armeabi, armeabi-v7a, mips, x86) in the jniLibs from the OpenCV SDK and make your gradle plugin above 0.7.2+

enter image description here

Solution 5:

The problem is that you are using Highgui.imread method before the OpenCV4Android library even finishes loading. Android calls the "onCreate" method before loading the OpenCV4Android library. So, create a separate method for your OpenCV code like this :-

publicclassStartextendsActivity {

@OverridepublicvoidonCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_start);
   }

@OverridepublicbooleanonCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_start, menu);
    returntrue;
   }

publicvoid readImage {
    MatImage= Highgui.imread("/image.jpg");
    if(Image=null) {
    Log.i("Start", "--------Image Cannot be Loaded--------");
    elseif(!Image=null) {
    Log.i("Start", "--------Image Loaded Successfully--------");
   }

}

Post a Comment for "Unsatisfied Link Error - Opencv For Android Non-native"