Android Emulator无法加载本机库

时间:2013-06-23 17:56:46

标签: java android opencv

我有一个关于拼接图像的项目,我使用的是opencv 2.4.5和java。我的所有代码都是java代码,当它是一个java项目时它运行得很完美。我将我的代码转移到android,导入opencv-245.jar和opencv_java245.dll到我的项目然后我配置了构建路径。但是当我的代码来到System.loadLibrary(...)时:

System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat image1= Highgui.imread( imgs.get(0).toString() , 1);
Mat image2= Highgui.imread( imgs.get(1).toString() , 1);
...

它出错并无法加载opencv本机库(opencv_java245.dll)。我在互联网上搜索并阅读了很多东西,但没有找到答案。他们中的大多数是关于android ndk但我不使用它,我的代码不是c ++。我试图使用System.load(路径),但它再次失败。请给我任何建议。谢谢。

更新: 堆栈跟踪:

06-23 18:23:37.884: E/AndroidRuntime(443): FATAL EXCEPTION: main
06-23 18:23:37.884: E/AndroidRuntime(443): java.lang.IllegalStateException: Could not execute method of the activity
06-23 18:23:37.884: E/AndroidRuntime(443):  at android.view.View$1.onClick(View.java:2704)
06-23 18:23:37.884: E/AndroidRuntime(443):  at android.view.View.performClick(View.java:3100)
06-23 18:23:37.884: E/AndroidRuntime(443):  at android.view.View$PerformClick.run(View.java:11644)
06-23 18:23:37.884: E/AndroidRuntime(443):  at android.os.Handler.handleCallback(Handler.java:587)
06-23 18:23:37.884: E/AndroidRuntime(443):  at android.os.Handler.dispatchMessage(Handler.java:92)
06-23 18:23:37.884: E/AndroidRuntime(443):  at android.os.Looper.loop(Looper.java:126)
06-23 18:23:37.884: E/AndroidRuntime(443):  at android.app.ActivityThread.main(ActivityThread.java:3997)
06-23 18:23:37.884: E/AndroidRuntime(443):  at java.lang.reflect.Method.invokeNative(Native Method)
06-23 18:23:37.884: E/AndroidRuntime(443):  at java.lang.reflect.Method.invoke(Method.java:491)
06-23 18:23:37.884: E/AndroidRuntime(443):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
06-23 18:23:37.884: E/AndroidRuntime(443):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
06-23 18:23:37.884: E/AndroidRuntime(443):  at dalvik.system.NativeStart.main(Native Method)
06-23 18:23:37.884: E/AndroidRuntime(443): Caused by: java.lang.reflect.InvocationTargetException
06-23 18:23:37.884: E/AndroidRuntime(443):  at java.lang.reflect.Method.invokeNative(Native Method)
06-23 18:23:37.884: E/AndroidRuntime(443):  at java.lang.reflect.Method.invoke(Method.java:491)
06-23 18:23:37.884: E/AndroidRuntime(443):  at android.view.View$1.onClick(View.java:2699)
06-23 18:23:37.884: E/AndroidRuntime(443):  ... 11 more
06-23 18:23:37.884: E/AndroidRuntime(443): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load opencv_java245: findLibrary returned null
06-23 18:23:37.884: E/AndroidRuntime(443):  at java.lang.Runtime.loadLibrary(Runtime.java:425)
06-23 18:23:37.884: E/AndroidRuntime(443):  at java.lang.System.loadLibrary(System.java:554)
06-23 18:23:37.884: E/AndroidRuntime(443):  at org.myproject.stitching_android.SDCardToGridView.onClickStitching(SDCardToGridView.java:90)
06-23 18:23:37.884: E/AndroidRuntime(443):  ... 14 more

1 个答案:

答案 0 :(得分:1)

基本问题是您尝试在Android设备上加载dll。 DLL是a Microsoft Windows only library,无法通过Android应用加载。


java.lang.UnsatisfiedLinkError: Cannot load library: load_library[1108]: Library '/data/data/org.myproject.stitching_android/lib/opencv_java245.dll' not found

意味着您的应用无法找到该文件,即使它找到了无法加载文件的文件,因为Android不支持DLL