I have OpenCV code (c++), which I want to use in Android. To do this I have to use Android NDK. I downloaded OpenCV package for Android development (ver. 2.4.0) and did all
Instead of loading your native library as
static{
System.loadLibrary("YOUR_LIBRARY");
}
load your library after opencv manager is connected in "onManagerConnected" method in you "BaseLoaderCallBack". Following is my code snippet working for me
public void onManagerConnected(int status) {
switch(status){
case LoaderCallbackInterface.SUCCESS:
Toast.makeText(getApplicationContext(), "manager connected", Toast.LENGTH_LONG).show();
System.loadLibrary("MYNATIVELIB");
break;
default:
super.onManagerConnected(status);
break;
}
}
You're at a higher level than the actual problem. See "Getting started with the NDK", when you run
cd <project>
<ndk>/ndk-build
... what does it say? (Remember to use the cygwin window and not a dos prompt).
Whoohoo!
Finally I found solution for this problem by myself!
I decided to debug line:
System.loadLibrary("native_sample");
To do this I downloaded android source code from Android-SDK and then attached source folder (/opt/android-sdk-linux/sources/android-15) to my project. After this I found that error was:
Cannot load library: link_image[1936]: 37 could not load needed library 'libopencv_java.so' for 'libhello-jni.so' (load_library[1091]: Library 'libopencv_java.so' not found)
And really this library is not in lib
directory. I don't know why but ndk-build
ignored it. So i decided to copy and load it manualy. For this I copied libopencv_java.so
from /opt/OpenCV-2.4.0/libs/armeabi-v7a
and also edited java code:
static {
System.loadLibrary("opencv_java"); //load opencv_java lib
System.loadLibrary("native_sample");
}
Actually similar problems are:
From second solution I found that I can load libraries using dlopen, but I haven't tried it yet.
So I will write simple bash-script that will do it (just copy) for myself.
Thanks to all.