Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Problem loading the jni lib with OCV Manager

Hello,

I had a simple app for LK tracking that was basically built following and slightly the "Tutorial 2 - mix Java+Native" of a older version of OCV (2.3.x i think). So now I'm trying to update the application in order to use it with the 2.4.3.

I succesfully managed to slightly change the code so i can use the 2.4.3 in a static way. Now I'd like to go further and update it to use the OCV Manager. Here come the problems. :(

Let me first recall that the architecture of the app is exactly the same as the old sample i mentioned before, so we have 3 files, with the main TrackingActivity, the TrackerBase Class with the threaded structure and the Tracker derived class that implements the method to be called whenever a frame is available.

I removed all the static loading code and added the new way of interacting with the manager to the main activity

public class TrackingActivity extends Activity 
{
 ...
private BaseLoaderCallback  mLoaderCallback = new BaseLoaderCallback(this) {  
    @Override
    public void onManagerConnected(int status) 
    {
        switch (status) {
            case LoaderCallbackInterface.SUCCESS:
            {
                Log.i(TAG, "OpenCV loaded successfully");

                // Load native library after(!) OpenCV initialization
                System.loadLibrary("LKTracker");

            } break;
            default:
            {
                Log.e(TAG, "problem loading OCV?");
                super.onManagerConnected(status);
            } break;
        }
    }
};
...
...
@Override
protected void onResume()
{
    // TODO Auto-generated method stub
    super.onResume();
    if( !OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback) )
    {
        Log.e(TAG, "Cannot connect to OpenCV Manager");
    }
}

So far so good. I also changed all the .mk files to resemble those of the official documentation and of the new samples of OCV 2.4.3. When i tried to execute the application (both on real devices and on the AVD) the OpenCV Manager is connected succefully and then when it comes to

System.loadLibrary("LKTracker");

I get this exception

11-06 14:46:31.224: I/Tracking::Activity(1461): OpenCV loaded successfully
11-06 14:46:31.224: D/dalvikvm(1461): Trying to load lib /data/data/com.example.lktracker/lib/libLKTracker.so 0x412a4d98
11-06 14:46:31.224: D/AndroidRuntime(1461): Shutting down VM
11-06 14:46:31.224: W/dalvikvm(1461): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
11-06 14:46:31.244: E/AndroidRuntime(1461): FATAL EXCEPTION: main
11-06 14:46:31.244: E/AndroidRuntime(1461): java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1285]:    36 cannot locate '_ZN2cv12_OutputArrayD1Ev'...
11-06 14:46:31.244: E/AndroidRuntime(1461):     at java.lang.Runtime.loadLibrary(Runtime.java:370)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at java.lang.System.loadLibrary(System.java:535)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at fr.lab.gipsa.lktracker.TrackingActivity$1.onManagerConnected(TrackingActivity.java:62)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at org.opencv.android.AsyncServiceHelper$1.onServiceConnected(AsyncServiceHelper.java:314)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1068)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1085)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at android.os.Handler.handleCallback(Handler.java:605)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at android.os.Looper.loop(Looper.java:137)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at android.app.ActivityThread.main(ActivityThread.java:4424)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at java.lang.reflect.Method.invokeNative(Native Method)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at java.lang.reflect.Method.invoke(Method.java:511)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at dalvik.system.NativeStart.main(Native Method)

It seems to me that it depends on some sort of error in build and linking the JNI part which is not properly linked with the OCV (i guess so form the ZN2cv12_OutputArrayD1Ev).

As a further test I imported the new sample 4 "Tutorial 4 Mix Java+Native" of OCV 2.4.3 and I tried to compile it and run it. It works on the AVD and on the device. So i started to compare the two JNI part to see if i missed something: the external builder in Eclipse is the same, the makefile .mk are identical (of course beside the different objects to build :-) ), the path to the OCV are the same (I attach at the end a sample of the building log).

The only difference between the two apps is that mine still use the old architecture whereas in the new one everything is done in the same activity class and the new camera interface is used. I don't know whether the problem may be loading the JNI library in a class different than the one that actually uses it (ie I load it in TrackingActivity instead of in the Tracker class). Could it be the problem? If it is so how can I do without changing the whole architecture?

Thank you very much in advance to whoever can give me a hint.

Simone


Here is the ndk building log of my application

rm -f ./libs/armeabi/lib*.so ./libs/armeabi-v7a/lib*.so ./libs/mips/lib*.so ./libs/x86/lib*.so
rm -f ./libs/armeabi/gdbserver ./libs/armeabi-v7a/gdbserver ./libs/mips/gdbserver ./libs/x86/gdbserver
Compile++ thumb  : LKTracker <= fr_lab_gipsa_lktracker_LKTracker.cpp
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-g++ -MMD -MP -MF ./obj/local/armeabi-v7a/objs/LKTracker/fr_lab_gipsa_lktracker_LKTracker.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__  -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -fno-exceptions -fno-rtti -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/android/build" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/include" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/include/opencv" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/contrib/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/legacy/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/ml/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/stitching/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/nonfree/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/objdetect/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/ts/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/videostab/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/calib3d/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/photo/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/video/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/features2d/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/highgui/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/androidcamera/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/flann/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/imgproc/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/core/include -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/include -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include -Ijni -DANDROID -fPIC -DANDROID -fsigned-char -ffast-math -O3 -funroll-loops -Wa,--noexecstack   -O2 -DNDEBUG -g -frtti -fexceptions  -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm/usr/include -c  jni/fr_lab_gipsa_lktracker_LKTracker.cpp -o ./obj/local/armeabi-v7a/objs/LKTracker/fr_lab_gipsa_lktracker_LKTracker.o 
rm -f ./libs/armeabi/gdb.setup ./libs/armeabi-v7a/gdb.setup ./libs/mips/gdb.setup ./libs/x86/gdb.setup
Compile++ thumb  : LKTracker <= LKTracker.cpp
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-g++ -MMD -MP -MF ./obj/local/armeabi-v7a/objs/LKTracker/LKTracker.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__  -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -fno-exceptions -fno-rtti -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/android/build" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/include" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/include/opencv" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/contrib/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/legacy/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/ml/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/stitching/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/nonfree/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/objdetect/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/ts/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/videostab/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/calib3d/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/photo/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/video/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/features2d/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/highgui/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/androidcamera/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/flann/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/imgproc/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/core/include -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/include -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include -Ijni -DANDROID -fPIC -DANDROID -fsigned-char -ffast-math -O3 -funroll-loops -Wa,--noexecstack   -O2 -DNDEBUG -g -frtti -fexceptions  -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm/usr/include -c  jni/LKTracker.cpp -o ./obj/local/armeabi-v7a/objs/LKTracker/LKTracker.o 
Prebuilt       : libgnustl_static.a <= <NDK>/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/
cp -f /home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/libgnustl_static.a obj/local/armeabi-v7a/libgnustl_static.a
In file included from jni/fr_lab_gipsa_lktracker_LKTracker.h:2:0,
                 from jni/fr_lab_gipsa_lktracker_LKTracker.cpp:21:
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm/usr/include/jni.h:592:13: note: the mangling of 'va_list' has changed in GCC 4.4
SharedLibrary  : libLKTracker.so
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-g++ -Wl,-soname,libLKTracker.so -shared --sysroot=/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm ./obj/local/armeabi-v7a/objs/LKTracker/fr_lab_gipsa_lktracker_LKTracker.o ./obj/local/armeabi-v7a/objs/LKTracker/LKTracker.o ./obj/local/armeabi-v7a/libgnustl_static.a  -Wl,--fix-cortex-a8  -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -L/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm/usr/lib -L/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/android/build/lib/armeabi-v7a -lopencv_java -llog -ldl -lc -lm -o obj/local/armeabi-v7a/libLKTracker.so
Install        : libLKTracker.so => libs/armeabi-v7a/libLKTracker.so
mkdir -p ./libs/armeabi-v7a
install -p ./obj/local/armeabi-v7a/libLKTracker.so ./libs/armeabi-v7a/libLKTracker.so
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded  ./libs/armeabi-v7a/libLKTracker.so

and this is the mixed4sample one

    rm -f ./libs/armeabi/lib*.so ./libs/armeabi-v7a/lib*.so ./libs/mips/lib*.so ./libs/x86/lib*.so
rm -f ./libs/armeabi/gdbserver ./libs/armeabi-v7a/gdbserver ./libs/mips/gdbserver ./libs/x86/gdbserver
Compile++ thumb  : mixed_sample <= jni_part.cpp
Prebuilt       : libgnustl_static.a <= <NDK>/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-g++ -MMD -MP -MF ./obj/local/armeabi-v7a/objs/mixed_sample/jni_part.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__  -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -fno-exceptions -fno-rtti -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/android/build" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/include" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/include/opencv" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/contrib/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/legacy/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/ml/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/stitching/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/nonfree/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/objdetect/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/ts/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/videostab/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/calib3d/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/photo/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/video/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/features2d/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/highgui/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/androidcamera/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/flann/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/imgproc/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/core/include -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/include -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include -Ijni -DANDROID -fPIC -DANDROID -fsigned-char -Wa,--noexecstack   -O2 -DNDEBUG -g -frtti -fexceptions  -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm/usr/include -c  jni/jni_part.cpp -o ./obj/local/armeabi-v7a/objs/mixed_sample/jni_part.o 
rm -f ./libs/armeabi/gdb.setup ./libs/armeabi-v7a/gdb.setup ./libs/mips/gdb.setup ./libs/x86/gdb.setup
cp -f /home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/libgnustl_static.a obj/local/armeabi-v7a/libgnustl_static.a
In file included from jni/jni_part.cpp:1:0:
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm/usr/include/jni.h:592:13: note: the mangling of 'va_list' has changed in GCC 4.4
SharedLibrary  : libmixed_sample.so
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-g++ -Wl,-soname,libmixed_sample.so -shared --sysroot=/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm ./obj/local/armeabi-v7a/objs/mixed_sample/jni_part.o ./obj/local/armeabi-v7a/libgnustl_static.a  -Wl,--fix-cortex-a8  -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -L/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm/usr/lib -L/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/android/build/lib/armeabi-v7a -lopencv_java -llog -ldl -lc -lm -o obj/local/armeabi-v7a/libmixed_sample.so
Install        : libmixed_sample.so => libs/armeabi-v7a/libmixed_sample.so
mkdir -p ./libs/armeabi-v7a
install -p ./obj/local/armeabi-v7a/libmixed_sample.so ./libs/armeabi-v7a/libmixed_sample.so
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded  ./libs/armeabi-v7a/libmixed_sample.so

they have the same path and the same options. There is actually this warning

android-ndk-r8b/platforms/android-8/arch-arm/usr/include/jni.h:592:13: note: the mangling of 'va_list' has changed in GCC 4.4

but I checked and it is harmless (and anyway it's in both, so it can't explain why one works and the other don't).

Problem loading the jni lib with OCV Manager

Hello,

I had a simple app for LK tracking that was basically built following and slightly the "Tutorial 2 - mix Java+Native" of a older version of OCV (2.3.x i think). So now I'm trying to update the application in order to use it with the 2.4.3.

I succesfully managed to slightly change the code so i can use the 2.4.3 in a static way. Now I'd like to go further and update it to use the OCV Manager. Here come the problems. :(

Let me first recall that the architecture of the app is exactly the same as the old sample i mentioned before, so we have 3 files, with the main TrackingActivity, the TrackerBase Class with the threaded structure and the Tracker derived class that implements the method to be called whenever a frame is available.

I removed all the static loading code and added the new way of interacting with the manager to the main activity

public class TrackingActivity extends Activity 
{
 ...
private BaseLoaderCallback  mLoaderCallback = new BaseLoaderCallback(this) {  
    @Override
    public void onManagerConnected(int status) 
    {
        switch (status) {
            case LoaderCallbackInterface.SUCCESS:
            {
                Log.i(TAG, "OpenCV loaded successfully");

                // Load native library after(!) OpenCV initialization
                System.loadLibrary("LKTracker");

            } break;
            default:
            {
                Log.e(TAG, "problem loading OCV?");
                super.onManagerConnected(status);
            } break;
        }
    }
};
...
...
@Override
protected void onResume()
{
    // TODO Auto-generated method stub
    super.onResume();
    if( !OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback) )
    {
        Log.e(TAG, "Cannot connect to OpenCV Manager");
    }
}

So far so good. I also changed all the .mk files to resemble those of the official documentation and of the new samples of OCV 2.4.3. When i tried to execute the application (both on real devices and on the AVD) the OpenCV Manager is connected succefully and then when it comes to

System.loadLibrary("LKTracker");

I get this exception

11-06 14:46:31.224: I/Tracking::Activity(1461): OpenCV loaded successfully
11-06 14:46:31.224: D/dalvikvm(1461): Trying to load lib /data/data/com.example.lktracker/lib/libLKTracker.so 0x412a4d98
11-06 14:46:31.224: D/AndroidRuntime(1461): Shutting down VM
11-06 14:46:31.224: W/dalvikvm(1461): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
11-06 14:46:31.244: E/AndroidRuntime(1461): FATAL EXCEPTION: main
11-06 14:46:31.244: E/AndroidRuntime(1461): java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1285]:    36 cannot locate '_ZN2cv12_OutputArrayD1Ev'...
11-06 14:46:31.244: E/AndroidRuntime(1461):     at java.lang.Runtime.loadLibrary(Runtime.java:370)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at java.lang.System.loadLibrary(System.java:535)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at fr.lab.gipsa.lktracker.TrackingActivity$1.onManagerConnected(TrackingActivity.java:62)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at org.opencv.android.AsyncServiceHelper$1.onServiceConnected(AsyncServiceHelper.java:314)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1068)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1085)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at android.os.Handler.handleCallback(Handler.java:605)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at android.os.Looper.loop(Looper.java:137)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at android.app.ActivityThread.main(ActivityThread.java:4424)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at java.lang.reflect.Method.invokeNative(Native Method)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at java.lang.reflect.Method.invoke(Method.java:511)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at dalvik.system.NativeStart.main(Native Method)

It seems to me that it depends on some sort of error in build and linking the JNI part which is not properly linked with the OCV (i guess so form the ZN2cv12_OutputArrayD1Ev).

As a further test I imported the new sample 4 "Tutorial 4 Mix Java+Native" of OCV 2.4.3 and I tried to compile it and run it. It works on the AVD and on the device. So i started to compare the two JNI part to see if i missed something: the external builder in Eclipse is the same, the makefile .mk are identical (of course beside the different objects to build :-) ), the path to the OCV are the same (I attach at the end a sample of the building log).

The only difference between the two apps is that mine still use the old architecture whereas in the new one everything is done in the same activity class and the new camera interface is used. I don't know whether the problem may be loading the JNI library in a class different than the one that actually uses it (ie I load it in TrackingActivity instead of in the Tracker class). Could it be the problem? If it is so how can I do without changing the whole architecture?

Thank you very much in advance to whoever can give me a hint.

Simone


----------

UPDATE:

Regarding my guess about importing the jni lib in a class different than the one using it, I noticed that the facedetection sample of OCV 2.4.3. has the same thing, the main activity class import the library which is then used by another class. So I imported it and tried to run it (again, everything seems to have the same settings) and I got again that kind of exception

11-06 16:44:36.194: E/AndroidRuntime(1642): FATAL EXCEPTION: main
11-06 16:44:36.194: E/AndroidRuntime(1642): java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1285]:    36 cannot locate '_ZN2cv21DetectionBasedTrackerC1ENS_3PtrINS0_9IDetectorEEES3_RKNS0_10ParametersE'...
11-06 16:44:36.194: E/AndroidRuntime(1642):     at java.lang.Runtime.loadLibrary(Runtime.java:370)
11-06 16:44:36.194: E/AndroidRuntime(1642):     at java.lang.System.loadLibrary(System.java:535)
11-06 16:44:36.194: E/AndroidRuntime(1642):     at org.opencv.samples.fd.FdActivity$1.onManagerConnected(FdActivity.java:67)
11-06 16:44:36.194: E/AndroidRuntime(1642):     at org.opencv.android.AsyncServiceHelper$1.onServiceConnected(AsyncServiceHelper.java:314)

So if the OCV guys does so, I guess it is possible. Still not a clue of what I am doing wrong

----------

Here is the ndk building log of my application

rm -f ./libs/armeabi/lib*.so ./libs/armeabi-v7a/lib*.so ./libs/mips/lib*.so ./libs/x86/lib*.so
rm -f ./libs/armeabi/gdbserver ./libs/armeabi-v7a/gdbserver ./libs/mips/gdbserver ./libs/x86/gdbserver
Compile++ thumb  : LKTracker <= fr_lab_gipsa_lktracker_LKTracker.cpp
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-g++ -MMD -MP -MF ./obj/local/armeabi-v7a/objs/LKTracker/fr_lab_gipsa_lktracker_LKTracker.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__  -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -fno-exceptions -fno-rtti -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/android/build" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/include" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/include/opencv" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/contrib/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/legacy/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/ml/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/stitching/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/nonfree/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/objdetect/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/ts/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/videostab/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/calib3d/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/photo/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/video/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/features2d/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/highgui/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/androidcamera/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/flann/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/imgproc/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/core/include -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/include -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include -Ijni -DANDROID -fPIC -DANDROID -fsigned-char -ffast-math -O3 -funroll-loops -Wa,--noexecstack   -O2 -DNDEBUG -g -frtti -fexceptions  -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm/usr/include -c  jni/fr_lab_gipsa_lktracker_LKTracker.cpp -o ./obj/local/armeabi-v7a/objs/LKTracker/fr_lab_gipsa_lktracker_LKTracker.o 
rm -f ./libs/armeabi/gdb.setup ./libs/armeabi-v7a/gdb.setup ./libs/mips/gdb.setup ./libs/x86/gdb.setup
Compile++ thumb  : LKTracker <= LKTracker.cpp
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-g++ -MMD -MP -MF ./obj/local/armeabi-v7a/objs/LKTracker/LKTracker.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__  -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -fno-exceptions -fno-rtti -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/android/build" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/include" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/include/opencv" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/contrib/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/legacy/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/ml/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/stitching/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/nonfree/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/objdetect/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/ts/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/videostab/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/calib3d/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/photo/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/video/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/features2d/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/highgui/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/androidcamera/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/flann/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/imgproc/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/core/include -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/include -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include -Ijni -DANDROID -fPIC -DANDROID -fsigned-char -ffast-math -O3 -funroll-loops -Wa,--noexecstack   -O2 -DNDEBUG -g -frtti -fexceptions  -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm/usr/include -c  jni/LKTracker.cpp -o ./obj/local/armeabi-v7a/objs/LKTracker/LKTracker.o 
Prebuilt       : libgnustl_static.a <= <NDK>/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/
cp -f /home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/libgnustl_static.a obj/local/armeabi-v7a/libgnustl_static.a
In file included from jni/fr_lab_gipsa_lktracker_LKTracker.h:2:0,
                 from jni/fr_lab_gipsa_lktracker_LKTracker.cpp:21:
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm/usr/include/jni.h:592:13: note: the mangling of 'va_list' has changed in GCC 4.4
SharedLibrary  : libLKTracker.so
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-g++ -Wl,-soname,libLKTracker.so -shared --sysroot=/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm ./obj/local/armeabi-v7a/objs/LKTracker/fr_lab_gipsa_lktracker_LKTracker.o ./obj/local/armeabi-v7a/objs/LKTracker/LKTracker.o ./obj/local/armeabi-v7a/libgnustl_static.a  -Wl,--fix-cortex-a8  -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -L/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm/usr/lib -L/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/android/build/lib/armeabi-v7a -lopencv_java -llog -ldl -lc -lm -o obj/local/armeabi-v7a/libLKTracker.so
Install        : libLKTracker.so => libs/armeabi-v7a/libLKTracker.so
mkdir -p ./libs/armeabi-v7a
install -p ./obj/local/armeabi-v7a/libLKTracker.so ./libs/armeabi-v7a/libLKTracker.so
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded  ./libs/armeabi-v7a/libLKTracker.so

and this is the mixed4sample one

    rm -f ./libs/armeabi/lib*.so ./libs/armeabi-v7a/lib*.so ./libs/mips/lib*.so ./libs/x86/lib*.so
rm -f ./libs/armeabi/gdbserver ./libs/armeabi-v7a/gdbserver ./libs/mips/gdbserver ./libs/x86/gdbserver
Compile++ thumb  : mixed_sample <= jni_part.cpp
Prebuilt       : libgnustl_static.a <= <NDK>/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-g++ -MMD -MP -MF ./obj/local/armeabi-v7a/objs/mixed_sample/jni_part.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__  -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -fno-exceptions -fno-rtti -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/android/build" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/include" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/include/opencv" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/contrib/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/legacy/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/ml/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/stitching/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/nonfree/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/objdetect/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/ts/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/videostab/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/calib3d/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/photo/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/video/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/features2d/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/highgui/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/androidcamera/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/flann/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/imgproc/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/core/include -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/include -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include -Ijni -DANDROID -fPIC -DANDROID -fsigned-char -Wa,--noexecstack   -O2 -DNDEBUG -g -frtti -fexceptions  -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm/usr/include -c  jni/jni_part.cpp -o ./obj/local/armeabi-v7a/objs/mixed_sample/jni_part.o 
rm -f ./libs/armeabi/gdb.setup ./libs/armeabi-v7a/gdb.setup ./libs/mips/gdb.setup ./libs/x86/gdb.setup
cp -f /home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/libgnustl_static.a obj/local/armeabi-v7a/libgnustl_static.a
In file included from jni/jni_part.cpp:1:0:
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm/usr/include/jni.h:592:13: note: the mangling of 'va_list' has changed in GCC 4.4
SharedLibrary  : libmixed_sample.so
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-g++ -Wl,-soname,libmixed_sample.so -shared --sysroot=/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm ./obj/local/armeabi-v7a/objs/mixed_sample/jni_part.o ./obj/local/armeabi-v7a/libgnustl_static.a  -Wl,--fix-cortex-a8  -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -L/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm/usr/lib -L/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/android/build/lib/armeabi-v7a -lopencv_java -llog -ldl -lc -lm -o obj/local/armeabi-v7a/libmixed_sample.so
Install        : libmixed_sample.so => libs/armeabi-v7a/libmixed_sample.so
mkdir -p ./libs/armeabi-v7a
install -p ./obj/local/armeabi-v7a/libmixed_sample.so ./libs/armeabi-v7a/libmixed_sample.so
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded  ./libs/armeabi-v7a/libmixed_sample.so

they have the same path and the same options. There is actually this warning

android-ndk-r8b/platforms/android-8/arch-arm/usr/include/jni.h:592:13: note: the mangling of 'va_list' has changed in GCC 4.4

but I checked and it is harmless (and anyway it's in both, so it can't explain why one works and the other don't).

Problem loading the jni lib with OCV Manager

Hello,

I had a simple app for LK tracking that was basically built following and slightly the "Tutorial 2 - mix Java+Native" of a older version of OCV (2.3.x i think). So now I'm trying to update the application in order to use it with the 2.4.3.

I succesfully managed to slightly change the code so i can use the 2.4.3 in a static way. Now I'd like to go further and update it to use the OCV Manager. Here come the problems. :(

Let me first recall that the architecture of the app is exactly the same as the old sample i mentioned before, so we have 3 files, with the main TrackingActivity, the TrackerBase Class with the threaded structure and the Tracker derived class that implements the method to be called whenever a frame is available.

I removed all the code for static loading code and added the new way of interacting with the manager to the main activity

public class TrackingActivity extends Activity 
{
 ...
private BaseLoaderCallback  mLoaderCallback = new BaseLoaderCallback(this) {  
    @Override
    public void onManagerConnected(int status) 
    {
        switch (status) {
            case LoaderCallbackInterface.SUCCESS:
            {
                Log.i(TAG, "OpenCV loaded successfully");

                // Load native library after(!) OpenCV initialization
                System.loadLibrary("LKTracker");

            } break;
            default:
            {
                Log.e(TAG, "problem loading OCV?");
                super.onManagerConnected(status);
            } break;
        }
    }
};
...
...
@Override
protected void onResume()
{
    // TODO Auto-generated method stub
    super.onResume();
    if( !OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback) )
    {
        Log.e(TAG, "Cannot connect to OpenCV Manager");
    }
}

So far so good. I also changed all the .mk files to resemble those of the official documentation and of the new samples of OCV 2.4.3. When i tried to execute the application (both on real devices and on the AVD) the OpenCV Manager is connected succefully and then when it comes to

System.loadLibrary("LKTracker");

I get this exception

11-06 14:46:31.224: I/Tracking::Activity(1461): OpenCV loaded successfully
11-06 14:46:31.224: D/dalvikvm(1461): Trying to load lib /data/data/com.example.lktracker/lib/libLKTracker.so 0x412a4d98
11-06 14:46:31.224: D/AndroidRuntime(1461): Shutting down VM
11-06 14:46:31.224: W/dalvikvm(1461): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
11-06 14:46:31.244: E/AndroidRuntime(1461): FATAL EXCEPTION: main
11-06 14:46:31.244: E/AndroidRuntime(1461): java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1285]:    36 cannot locate '_ZN2cv12_OutputArrayD1Ev'...
11-06 14:46:31.244: E/AndroidRuntime(1461):     at java.lang.Runtime.loadLibrary(Runtime.java:370)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at java.lang.System.loadLibrary(System.java:535)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at fr.lab.gipsa.lktracker.TrackingActivity$1.onManagerConnected(TrackingActivity.java:62)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at org.opencv.android.AsyncServiceHelper$1.onServiceConnected(AsyncServiceHelper.java:314)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1068)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1085)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at android.os.Handler.handleCallback(Handler.java:605)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at android.os.Looper.loop(Looper.java:137)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at android.app.ActivityThread.main(ActivityThread.java:4424)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at java.lang.reflect.Method.invokeNative(Native Method)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at java.lang.reflect.Method.invoke(Method.java:511)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-06 14:46:31.244: E/AndroidRuntime(1461):     at dalvik.system.NativeStart.main(Native Method)

It seems to me that it depends on some sort of error in build and linking the JNI part which is not properly linked with the OCV (i guess so form the ZN2cv12_OutputArrayD1Ev).

As a further test I imported the new sample 4 "Tutorial 4 Mix Java+Native" of OCV 2.4.3 and I tried to compile it and run it. It works on the AVD and on the device. So i started to compare the two JNI part to see if i missed something: the external builder in Eclipse is the same, the makefile .mk are identical (of course beside the different objects to build :-) ), the path to the OCV are the same (I attach at the end a sample of the building log).

The only difference between the two apps is that mine still use the old architecture whereas in the new one everything is done in the same activity class and the new camera interface is used. I don't know whether the problem may be loading the JNI library in a class different than the one that actually uses it (ie I load it in TrackingActivity instead of in the Tracker class). Could it be the problem? If it is so how can I do without changing the whole architecture?

Thank you very much in advance to whoever can give me a hint.

Simone

----------

UPDATE:

Regarding my guess about importing the jni lib in a class different than the one using it, I noticed that the facedetection sample of OCV 2.4.3. has the same thing, the main activity class import the library which is then used by another class. So I imported it and tried to run it (again, everything seems to have the same settings) and I got again that kind of exception

11-06 16:44:36.194: E/AndroidRuntime(1642): FATAL EXCEPTION: main
11-06 16:44:36.194: E/AndroidRuntime(1642): java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1285]:    36 cannot locate '_ZN2cv21DetectionBasedTrackerC1ENS_3PtrINS0_9IDetectorEEES3_RKNS0_10ParametersE'...
11-06 16:44:36.194: E/AndroidRuntime(1642):     at java.lang.Runtime.loadLibrary(Runtime.java:370)
11-06 16:44:36.194: E/AndroidRuntime(1642):     at java.lang.System.loadLibrary(System.java:535)
11-06 16:44:36.194: E/AndroidRuntime(1642):     at org.opencv.samples.fd.FdActivity$1.onManagerConnected(FdActivity.java:67)
11-06 16:44:36.194: E/AndroidRuntime(1642):     at org.opencv.android.AsyncServiceHelper$1.onServiceConnected(AsyncServiceHelper.java:314)

So if the OCV guys does so, I guess it is possible. Still not a clue of what I am doing wrong

----------

Here is the ndk building log of my application

rm -f ./libs/armeabi/lib*.so ./libs/armeabi-v7a/lib*.so ./libs/mips/lib*.so ./libs/x86/lib*.so
rm -f ./libs/armeabi/gdbserver ./libs/armeabi-v7a/gdbserver ./libs/mips/gdbserver ./libs/x86/gdbserver
Compile++ thumb  : LKTracker <= fr_lab_gipsa_lktracker_LKTracker.cpp
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-g++ -MMD -MP -MF ./obj/local/armeabi-v7a/objs/LKTracker/fr_lab_gipsa_lktracker_LKTracker.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__  -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -fno-exceptions -fno-rtti -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/android/build" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/include" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/include/opencv" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/contrib/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/legacy/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/ml/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/stitching/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/nonfree/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/objdetect/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/ts/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/videostab/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/calib3d/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/photo/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/video/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/features2d/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/highgui/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/androidcamera/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/flann/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/imgproc/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/core/include -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/include -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include -Ijni -DANDROID -fPIC -DANDROID -fsigned-char -ffast-math -O3 -funroll-loops -Wa,--noexecstack   -O2 -DNDEBUG -g -frtti -fexceptions  -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm/usr/include -c  jni/fr_lab_gipsa_lktracker_LKTracker.cpp -o ./obj/local/armeabi-v7a/objs/LKTracker/fr_lab_gipsa_lktracker_LKTracker.o 
rm -f ./libs/armeabi/gdb.setup ./libs/armeabi-v7a/gdb.setup ./libs/mips/gdb.setup ./libs/x86/gdb.setup
Compile++ thumb  : LKTracker <= LKTracker.cpp
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-g++ -MMD -MP -MF ./obj/local/armeabi-v7a/objs/LKTracker/LKTracker.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__  -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -fno-exceptions -fno-rtti -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/android/build" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/include" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/include/opencv" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/contrib/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/legacy/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/ml/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/stitching/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/nonfree/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/objdetect/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/ts/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/videostab/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/calib3d/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/photo/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/video/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/features2d/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/highgui/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/androidcamera/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/flann/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/imgproc/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/core/include -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/include -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include -Ijni -DANDROID -fPIC -DANDROID -fsigned-char -ffast-math -O3 -funroll-loops -Wa,--noexecstack   -O2 -DNDEBUG -g -frtti -fexceptions  -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm/usr/include -c  jni/LKTracker.cpp -o ./obj/local/armeabi-v7a/objs/LKTracker/LKTracker.o 
Prebuilt       : libgnustl_static.a <= <NDK>/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/
cp -f /home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/libgnustl_static.a obj/local/armeabi-v7a/libgnustl_static.a
In file included from jni/fr_lab_gipsa_lktracker_LKTracker.h:2:0,
                 from jni/fr_lab_gipsa_lktracker_LKTracker.cpp:21:
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm/usr/include/jni.h:592:13: note: the mangling of 'va_list' has changed in GCC 4.4
SharedLibrary  : libLKTracker.so
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-g++ -Wl,-soname,libLKTracker.so -shared --sysroot=/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm ./obj/local/armeabi-v7a/objs/LKTracker/fr_lab_gipsa_lktracker_LKTracker.o ./obj/local/armeabi-v7a/objs/LKTracker/LKTracker.o ./obj/local/armeabi-v7a/libgnustl_static.a  -Wl,--fix-cortex-a8  -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -L/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm/usr/lib -L/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/android/build/lib/armeabi-v7a -lopencv_java -llog -ldl -lc -lm -o obj/local/armeabi-v7a/libLKTracker.so
Install        : libLKTracker.so => libs/armeabi-v7a/libLKTracker.so
mkdir -p ./libs/armeabi-v7a
install -p ./obj/local/armeabi-v7a/libLKTracker.so ./libs/armeabi-v7a/libLKTracker.so
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded  ./libs/armeabi-v7a/libLKTracker.so

and this is the mixed4sample one

    rm -f ./libs/armeabi/lib*.so ./libs/armeabi-v7a/lib*.so ./libs/mips/lib*.so ./libs/x86/lib*.so
rm -f ./libs/armeabi/gdbserver ./libs/armeabi-v7a/gdbserver ./libs/mips/gdbserver ./libs/x86/gdbserver
Compile++ thumb  : mixed_sample <= jni_part.cpp
Prebuilt       : libgnustl_static.a <= <NDK>/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-g++ -MMD -MP -MF ./obj/local/armeabi-v7a/objs/mixed_sample/jni_part.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__  -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -fno-exceptions -fno-rtti -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/android/build" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/include" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/include/opencv" -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/contrib/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/legacy/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/ml/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/stitching/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/nonfree/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/objdetect/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/ts/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/videostab/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/calib3d/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/photo/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/video/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/features2d/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/highgui/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/androidcamera/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/flann/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/imgproc/include -I"/home/simone/MOOV3D/dev/code/libs/opencv2.4.3"/modules/core/include -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/include -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include -Ijni -DANDROID -fPIC -DANDROID -fsigned-char -Wa,--noexecstack   -O2 -DNDEBUG -g -frtti -fexceptions  -I/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm/usr/include -c  jni/jni_part.cpp -o ./obj/local/armeabi-v7a/objs/mixed_sample/jni_part.o 
rm -f ./libs/armeabi/gdb.setup ./libs/armeabi-v7a/gdb.setup ./libs/mips/gdb.setup ./libs/x86/gdb.setup
cp -f /home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/libgnustl_static.a obj/local/armeabi-v7a/libgnustl_static.a
In file included from jni/jni_part.cpp:1:0:
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm/usr/include/jni.h:592:13: note: the mangling of 'va_list' has changed in GCC 4.4
SharedLibrary  : libmixed_sample.so
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-g++ -Wl,-soname,libmixed_sample.so -shared --sysroot=/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm ./obj/local/armeabi-v7a/objs/mixed_sample/jni_part.o ./obj/local/armeabi-v7a/libgnustl_static.a  -Wl,--fix-cortex-a8  -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -L/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/platforms/android-8/arch-arm/usr/lib -L/home/simone/MOOV3D/dev/code/libs/opencv2.4.3/android/build/lib/armeabi-v7a -lopencv_java -llog -ldl -lc -lm -o obj/local/armeabi-v7a/libmixed_sample.so
Install        : libmixed_sample.so => libs/armeabi-v7a/libmixed_sample.so
mkdir -p ./libs/armeabi-v7a
install -p ./obj/local/armeabi-v7a/libmixed_sample.so ./libs/armeabi-v7a/libmixed_sample.so
/home/simone/MOOV3D/dev/code/libs/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded  ./libs/armeabi-v7a/libmixed_sample.so

they have the same path and the same options. There is actually this warning

android-ndk-r8b/platforms/android-8/arch-arm/usr/include/jni.h:592:13: note: the mangling of 'va_list' has changed in GCC 4.4

but I checked and it is harmless (and anyway it's in both, so it can't explain why one works and the other don't).