我尝试在模拟器上运行opencv android示例。具有本机代码的样本,例如示例“教程2高级 - 1.添加Native OpenCV”失败。我有一个Win7 x86系统。我可以构建本机库,但如果我运行示例,我总是得到以下异常:
10-04 08:08:19.179: WARN/dalvikvm(696): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lorg/opencv/samples/tutorial3/Sample3View;
10-04 08:08:19.190: DEBUG/AndroidRuntime(696): Shutting down VM
10-04 08:08:19.190: WARN/dalvikvm(696): threadid=1: thread exiting with uncaught exception (group=0x40015560)
10-04 08:08:19.289: ERROR/AndroidRuntime(696): FATAL EXCEPTION: main
10-04 08:08:19.289: ERROR/AndroidRuntime(696): java.lang.ExceptionInInitializerError
10-04 08:08:19.289: ERROR/AndroidRuntime(696): at org.opencv.samples.tutorial3.Sample3Native.onCreate(Sample3Native.java:23)
10-04 08:08:19.289: ERROR/AndroidRuntime(696): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-04 08:08:19.289: ERROR/AndroidRuntime(696): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
10-04 08:08:19.289: ERROR/AndroidRuntime(696): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
10-04 08:08:19.289: ERROR/AndroidRuntime(696): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-04 08:08:19.289: ERROR/AndroidRuntime(696): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
10-04 08:08:19.289: ERROR/AndroidRuntime(696): at android.os.Handler.dispatchMessage(Handler.java:99)
10-04 08:08:19.289: ERROR/AndroidRuntime(696): at android.os.Looper.loop(Looper.java:123)
10-04 08:08:19.289: ERROR/AndroidRuntime(696): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-04 08:08:19.289: ERROR/AndroidRuntime(696): at java.lang.reflect.Method.invokeNative(Native Method)
10-04 08:08:19.289: ERROR/AndroidRuntime(696): at java.lang.reflect.Method.invoke(Method.java:507)
10-04 08:08:19.289: ERROR/AndroidRuntime(696): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-04 08:08:19.289: ERROR/AndroidRuntime(696): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-04 08:08:19.289: ERROR/AndroidRuntime(696): at dalvik.system.NativeStart.main(Native Method)
10-04 08:08:19.289: ERROR/AndroidRuntime(696): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load native_sample: findLibrary returned null
10-04 08:08:19.289: ERROR/AndroidRuntime(696): at java.lang.Runtime.loadLibrary(Runtime.java:429)
10-04 08:08:19.289: ERROR/AndroidRuntime(696): at java.lang.System.loadLibrary(System.java:554)
10-04 08:08:19.289: ERROR/AndroidRuntime(696): at org.opencv.samples.tutorial3.Sample3View.(Sample3View.java:27)
10-04 08:08:19.289: ERROR/AndroidRuntime(696): ... 14 more
10-04 08:08:19.389: WARN/ActivityManager(70): Force finishing activity org.opencv.samples.tutorial3/.Sample3Native
10-04 08:08:19.959: WARN/ActivityManager(70): Activity pause timeout for HistoryRecord{406f26a0 org.opencv.samples.tutorial3/.Sample3Native}
10-04 08:08:20.089: DEBUG/dalvikvm(70): GC_EXPLICIT freed 92K, 47% free 4404K/8263K, external 5449K/5830K, paused 103ms
任何想法,如何解决这个问题? 感谢
答案 0 :(得分:15)
更改行
APP_ABI := armeabi-v7a
在jni/Application.mk
到
APP_ABI := armeabi
默认情况下,为现代armv7-a硬件配置OpenCV示例。
答案 1 :(得分:4)
Andrey Kamaev真的很好的回答!
以下是我从我的经历中学到的东西:
如果你知道你的硬件细节(对于你的情况是它的x86)..你可以定义如下:
APP_ABI:= x86
我们也可以在jni / Application.mk中定义如下:
APP_ABI:= armeabi armeabi-v7a x86
现在,当我们构建应用程序时,将创建3个共享对象库文件。然后当我们运行应用程序时,基于目标设备将加载相应的库。
当我在平板电脑中运行示例OpenCV Android原生应用程序时(作为其硬件支持armeabi-v7a),它工作正常,但同样的应用程序无法在我的三星Galaxy ACE移动设备上运行(没有armeabi-v7a支持)。
所以,我设置APP_ABI:= armeabi armeabi-v7a,现在应用程序在平板电脑和手机中运行良好:)