无法在OpenCV的机器人样品链接本机库 [英] Unable to link native library in OpenCV Android sample

查看:127
本文介绍了无法在OpenCV的机器人样品链接本机库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的OpenCV code(C ++),我想在Android中使用。要做到这一点我必须使用<一个href="http://opencv.itseez.com/doc/tutorials/introduction/android_binary_package/android_binary_package_using_with_NDK.html">Android NDK 。我下载 OpenCV的包为Android开发(版本2.4.0),并做了所有步骤,从该手册。基本样品(的Java API只)运行没有问题。样品#3的(教程3(高级) - 添加本机OpenCV的)的正确建立从NDK建设者。但是,总是有当我试图运行/从日食它在设备调试异常:

 异常Ljava /朗/的UnsatisfiedLinkError;扔在初始化Lorg / OpenCV的/样本/ tutorial3 / Sample3View;
 

在这一行:

 的System.loadLibrary(native_sample);
 

下面是饱满的logcat日志:

  05-31 23:41:45.976:W / ActivityThread(9708):应用org.opencv.samples.tutorial3正在等待调试器在端口8100 ...
05-31 23:41:45.983:我/的System.out(9708):发送等待块
05-31 23:41:45.983:I / dalvikvm(9708):调试器被激活
05-31 23:41:46.179:我/的System.out(9708):调试器连接
05-31 23:41:46.179:我/的System.out(9708):等待调试器来解决?
05-31 23:41:46.382:我/的System.out(9708):等待调试器来解决?
05-31 23:41:46.585:我/的System.out(9708):等待调试器来解决?
05-31 23:41:46.788:我/的System.out(9708):等待调试器来解决?
05-31 23:41:46.983:我/的System.out(9708):等待调试器来解决?
05-31 23:41:47.186:我/的System.out(9708):等待调试器来解决?
05-31 23:41:47.389:我/的System.out(9708):等待调试器来解决?
05-31 23:41:47.585:我/的System.out(9708):等待调试器来解决?
05-31 23:41:47.788:我/的System.out(9708):调试器已落户(1463)
05-31 23:41:47.819:D / szipinf(9708):初始化膨胀状态
05-31 23:41:47.866:I /样品::活动(9708):实例化新类org.opencv.samples.tutorial3.Sample3Native
05-31 23:41:48.909:D / dalvikvm(9708):主题ID = 1:仍暂停撤消后(SC = 1 DC = 1)
05-31 23:41:51.770:I /样品::活动(9708):的onCreate
05-31 23:41:59.283:W / dalvikvm(9708):异常Ljava /朗/的UnsatisfiedLinkError;扔在初始化Lorg / OpenCV的/样本/ tutorial3 / Sample3View;
05-31 23:42:01.965:D / AndroidRuntime(9708):关闭虚拟机
05-31 23:42:01.965:W / dalvikvm(9708):主题ID = 1:螺纹退出与未捕获的异常(组= 0x40015560)
05-31 23:42:01.999:E / AndroidRuntime(9708):致命异常:主要
05-31 23:42:01.999:E / AndroidRuntime(9708):java.lang.ExceptionInInitializerError
05-31 23:42:01.999:E / AndroidRuntime(9708):在org.opencv.samples.tutorial3.Sample3Native.onCreate(Sample3Native.java:21)
05-31 23:42:01.999:E / AndroidRuntime(9708):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-31 23:42:01.999:E / AndroidRuntime(9708):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
05-31 23:42:01.999:E / AndroidRuntime(9708):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
05-31 23:42:01.999:E / AndroidRuntime(9708):在android.app.ActivityThread.access $ 1500(ActivityThread.java:123)
05-31 23:42:01.999:E / AndroidRuntime(9708):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:939)
05-31 23:42:01.999:E / AndroidRuntime(9708):在android.os.Handler.dispatchMessage(Handler.java:99)
05-31 23:42:01.999:E / AndroidRuntime(9708):在android.os.Looper.loop(Looper.java:130)
05-31 23:42:01.999:E / AndroidRuntime(9708):在android.app.ActivityThread.main(ActivityThread.java:3835)
05-31 23:42:01.999:E / AndroidRuntime(9708):在java.lang.reflect.Method.invokeNative(本机方法)
05-31 23:42:01.999:E / AndroidRuntime(9708):在java.lang.reflect.Method.invoke(Method.java:507)
05-31 23:42:01.999:E / AndroidRuntime(9708):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:864)
05-31 23:42:01.999:E / AndroidRuntime(9708):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
05-31 23:42:01.999:E / AndroidRuntime(9708):在dalvik.system.NativeStart.main(本机方法)
05-31 23:42:01.999:E / AndroidRuntime(9708):java.lang.UnsatisfiedLinkError中:产生的原因无法加载native_sample:findLibrary返回null
05-31 23:42:01.999:E / AndroidRuntime(9708):在java.lang.Runtime.loadLibrary(Runtime.java:429)
05-31 23:42:01.999:E / AndroidRuntime(9708):在java.lang.System.loadLibrary(System.java:554)
05-31 23:42:01.999:E / AndroidRuntime(9708):在org.opencv.samples.tutorial3.Sample3View&LT; clinit&GT;(Sample3View.java:48)
05-31 23:42:01.999:E / AndroidRuntime(9708):14 ...更多
 

我找到了同样的问题解决方案,但没有人对我没有帮助:

  1. <一个href="http://stackoverflow.com/questions/7645301/native-opencv-samples-for-android-throws-unsatisfiedlinkerror">Native OpenCV的样品为Android抛出的UnsatisfiedLinkError
  2. <一个href="https://groups.google.com/forum/?fromgroups#!topic/android-opencv/NpnKPVdwzJ4">java.lang.UnsatisfiedLinkError:无法加载opencv_java:findLibrary返回null
  3. 主要OpenCV的,Android的的Windows安装和运行问题(无答案)

另外,我已经在不同的设备和Android的API版本进行了测试。

我的系统配置:

 阿斯特@阿斯特-K42Jv:〜$的uname -a
Linux的阿斯特-K42Jv 3.2.0-24  - 仿制PAE#39,Ubuntu的SMP周一5月21日18时54分21秒UTC 2012 i686的的i686 i386的GNU / Linux的
 


我一直在试图解决这个问题了4晚(这是我的自由时间:)),但没有运气。我真的需要为我的论文,所以任何帮助将AP preciated。


更新:我在Windows 7(64)测试此样本,但结果是一样的。

看来,这是OpenCV的错误。


更新:生成日志:

 阿斯特@阿斯特-K42Jv:/opt/eclipse-android/workspace/OpenCV-2.4.0-samples/tutorial-3-native$ NDK建造
安装:libnative_camera_r2.2.0.so =&GT;库/ armeabi-V7A / libnative_camera_r2.2.0.so
安装:libnative_camera_r2.3.3.so =&GT;库/ armeabi-V7A / libnative_camera_r2.3.3.so
安装:libnative_camera_r3.0.1.so =&GT;库/ armeabi-V7A / libnative_camera_r3.0.1.so
安装:libnative_camera_r4.0.0.so =&GT;库/ armeabi-V7A / libnative_camera_r4.0.0.so
安装:libnative_camera_r4.0.3.so =&GT;库/ armeabi-V7A / libnative_camera_r4.0.3.so
安装:libnative_sample.so =&GT;库/ armeabi-V7A / libnative_sample.so
 

解决方案

Whoohoo!

最后,我发现这个问题的解决方案,由我自己!

我决定要调试行:

 的System.loadLibrary(native_sample);
 

要做到这一点,我下载了Android的源$ C ​​$ C从Android的SDK,然后附带的源文件夹中的(/ OPT / Android的SDK-Linux的/来源/机器人-15)的到我的项目。 在此之后,我发现这个错误是:

 无法加载库:link_image [1936年]:37无法加载所需的库'libopencv_java.so'为'libhello-jni.so'(load_library [1091]:图书馆libopencv_java。所以未找到)
 

和真的没有这个库的 LIB 目录。我不知道为什么,但 NDK建造忽略了它。所以我决定复制并加载它manualy。为此,我抄 libopencv_java.so /opt/OpenCV-2.4.0/libs/armeabi-v7a ,也编辑Java的code:

 静态{
    的System.loadLibrary(opencv_java); //负荷opencv_java LIB
    的System.loadLibrary(native_sample);
}
 

其实类似的问题有:

  1. 无法在necessitas加载opencv的库
  2. <一个href="http://stackoverflow.com/questions/9958549/android-opencv-cannot-dlopen-camera-wrapper-library">Android OpenCV的:不能dlopen的相机包装库

这是第二个解决方案,我发现我可以使用的dlopen 加载库,但我的避风港'牛逼尝试过呢。

所以,我会写简单的bash脚本,将做到这一点(只是复制)为我自己。

感谢所有。

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 steps from that manual. Basic samples (Java API only) run without problems. Sample #3 (Tutorial 3 (Advanced) - Add Native OpenCV) builds from ndk-builder correctly. But always got exception when I'm trying to run/debug it on device from eclipse:

Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lorg/opencv/samples/tutorial3/Sample3View;

In this line:

System.loadLibrary("native_sample");

Here's full logcat log:

05-31 23:41:45.976: W/ActivityThread(9708): Application org.opencv.samples.tutorial3 is waiting for the debugger on port 8100...
05-31 23:41:45.983: I/System.out(9708): Sending WAIT chunk
05-31 23:41:45.983: I/dalvikvm(9708): Debugger is active
05-31 23:41:46.179: I/System.out(9708): Debugger has connected
05-31 23:41:46.179: I/System.out(9708): waiting for debugger to settle...
05-31 23:41:46.382: I/System.out(9708): waiting for debugger to settle...
05-31 23:41:46.585: I/System.out(9708): waiting for debugger to settle...
05-31 23:41:46.788: I/System.out(9708): waiting for debugger to settle...
05-31 23:41:46.983: I/System.out(9708): waiting for debugger to settle...
05-31 23:41:47.186: I/System.out(9708): waiting for debugger to settle...
05-31 23:41:47.389: I/System.out(9708): waiting for debugger to settle...
05-31 23:41:47.585: I/System.out(9708): waiting for debugger to settle...
05-31 23:41:47.788: I/System.out(9708): debugger has settled (1463)
05-31 23:41:47.819: D/szipinf(9708): Initializing inflate state
05-31 23:41:47.866: I/Sample::Activity(9708): Instantiated new class org.opencv.samples.tutorial3.Sample3Native
05-31 23:41:48.909: D/dalvikvm(9708): threadid=1: still suspended after undo (sc=1 dc=1)
05-31 23:41:51.770: I/Sample::Activity(9708): onCreate
05-31 23:41:59.283: W/dalvikvm(9708): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lorg/opencv/samples/tutorial3/Sample3View;
05-31 23:42:01.965: D/AndroidRuntime(9708): Shutting down VM
05-31 23:42:01.965: W/dalvikvm(9708): threadid=1: thread exiting with uncaught exception (group=0x40015560)
05-31 23:42:01.999: E/AndroidRuntime(9708): FATAL EXCEPTION: main
05-31 23:42:01.999: E/AndroidRuntime(9708): java.lang.ExceptionInInitializerError
05-31 23:42:01.999: E/AndroidRuntime(9708):     at org.opencv.samples.tutorial3.Sample3Native.onCreate(Sample3Native.java:21)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at android.app.ActivityThread.access$1500(ActivityThread.java:123)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at android.os.Looper.loop(Looper.java:130)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at android.app.ActivityThread.main(ActivityThread.java:3835)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at java.lang.reflect.Method.invokeNative(Native Method)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at java.lang.reflect.Method.invoke(Method.java:507)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at dalvik.system.NativeStart.main(Native Method)
05-31 23:42:01.999: E/AndroidRuntime(9708): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load native_sample: findLibrary returned null
05-31 23:42:01.999: E/AndroidRuntime(9708):     at java.lang.Runtime.loadLibrary(Runtime.java:429)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at java.lang.System.loadLibrary(System.java:554)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at org.opencv.samples.tutorial3.Sample3View.<clinit>(Sample3View.java:48)
05-31 23:42:01.999: E/AndroidRuntime(9708):     ... 14 more

I find solutions for the same problem but none of them didn't help me:

  1. Native OpenCV Samples for Android throws UnsatisfiedLinkError
  2. java.lang.UnsatisfiedLinkError: Couldn't load opencv_java: findLibrary returned null
  3. Major OpenCV-Android for Windows Installing and Running Issues (no answer)

Also I have tested it on different devices and Android API versions.

My system configuration:

astor@astor-K42Jv:~$ uname -a
Linux astor-K42Jv 3.2.0-24-generic-pae #39-Ubuntu SMP Mon May 21 18:54:21 UTC 2012 i686 i686 i386 GNU/Linux


I've been tried to fix this problem for 4 nights (it's my free time :) ), but with no luck. I really need this for my thesis, so any help will be appreciated.


Update: I have tested this sample on Windows 7 (64), but result is the same.

It seems that this is OpenCV bug.


Update: Build log:

astor@astor-K42Jv:/opt/eclipse-android/workspace/OpenCV-2.4.0-samples/tutorial-3-native$ ndk-build 
Install        : libnative_camera_r2.2.0.so => libs/armeabi-v7a/libnative_camera_r2.2.0.so
Install        : libnative_camera_r2.3.3.so => libs/armeabi-v7a/libnative_camera_r2.3.3.so
Install        : libnative_camera_r3.0.1.so => libs/armeabi-v7a/libnative_camera_r3.0.1.so
Install        : libnative_camera_r4.0.0.so => libs/armeabi-v7a/libnative_camera_r4.0.0.so
Install        : libnative_camera_r4.0.3.so => libs/armeabi-v7a/libnative_camera_r4.0.3.so
Install        : libnative_sample.so => libs/armeabi-v7a/libnative_sample.so

解决方案

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:

  1. Can not load Opencv libraries in necessitas
  2. Android OpenCV: cannot dlopen camera wrapper library

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.

这篇关于无法在OpenCV的机器人样品链接本机库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆