我遵循了 javacv 中的 cppjars zip 文件中包含的自述文件,我能够成功构建库,但是当我使用新的 .so 文件运行我的应用程序时,我得到一个 java.lang.UnsatisfiedLinkError 但所有的 .so文件存在于 armeabi 文件夹中。触发此异常的代码行如下所示
yuvIplimage = IplImage.create(imageWidth, imageHeight, IPL_DEPTH_8U, 2);
例外是这个
04-29 15:40:46.610: E/AndroidRuntime(23057): FATAL EXCEPTION: main
04-29 15:40:46.610: E/AndroidRuntime(23057): java.lang.ExceptionInInitializerError
04-29 15:40:46.610: E/AndroidRuntime(23057): at com.sample.Stream.initRecorder(Stream.java:84)
04-29 15:40:46.610: E/AndroidRuntime(23057): at com.sample.Stream.onCreate(Stream.java:77)
04-29 15:40:46.610: E/AndroidRuntime(23057): at android.app.Activity.performCreate(Activity.java:4469)
04-29 15:40:46.610: E/AndroidRuntime(23057): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
04-29 15:40:46.610: E/AndroidRuntime(23057): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
04-29 15:40:46.610: E/AndroidRuntime(23057): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
04-29 15:40:46.610: E/AndroidRuntime(23057): at android.app.ActivityThread.access$600(ActivityThread.java:127)
04-29 15:40:46.610: E/AndroidRuntime(23057): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
04-29 15:40:46.610: E/AndroidRuntime(23057): at android.os.Handler.dispatchMessage(Handler.java:99)
04-29 15:40:46.610: E/AndroidRuntime(23057): at android.os.Looper.loop(Looper.java:137)
04-29 15:40:46.610: E/AndroidRuntime(23057): at android.app.ActivityThread.main(ActivityThread.java:4507)
04-29 15:40:46.610: E/AndroidRuntime(23057): at java.lang.reflect.Method.invokeNative(Native Method)
04-29 15:40:46.610: E/AndroidRuntime(23057): at java.lang.reflect.Method.invoke(Method.java:511)
04-29 15:40:46.610: E/AndroidRuntime(23057): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:978)
04-29 15:40:46.610: E/AndroidRuntime(23057): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
04-29 15:40:46.610: E/AndroidRuntime(23057): at dalvik.system.NativeStart.main(Native Method)
04-29 15:40:46.610: E/AndroidRuntime(23057): Caused by: java.lang.ExceptionInInitializerError
04-29 15:40:46.610: E/AndroidRuntime(23057): at java.lang.Class.classForName(Native Method)
04-29 15:40:46.610: E/AndroidRuntime(23057): at java.lang.Class.forName(Class.java:217)
04-29 15:40:46.610: E/AndroidRuntime(23057): at com.googlecode.javacpp.Loader.load(Loader.java:338)
04-29 15:40:46.610: E/AndroidRuntime(23057): at com.googlecode.javacpp.Loader.load(Loader.java:319)
04-29 15:40:46.610: E/AndroidRuntime(23057): at com.googlecode.javacv.cpp.opencv_core$CvArr.<clinit>(opencv_core.java:163)
04-29 15:40:46.610: E/AndroidRuntime(23057): ... 16 more
04-29 15:40:46.610: E/AndroidRuntime(23057): Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1965]: 108 could not load needed library 'libopencv_core.so' for 'libjniopencv_core.so' (find_library[1200]: 108 'libopencv_core.so' failed to load previously)
04-29 15:40:46.610: E/AndroidRuntime(23057): at java.lang.Runtime.loadLibrary(Runtime.java:370)
04-29 15:40:46.610: E/AndroidRuntime(23057): at java.lang.System.loadLibrary(System.java:535)
04-29 15:40:46.610: E/AndroidRuntime(23057): at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:448)
04-29 15:40:46.610: E/AndroidRuntime(23057): at com.googlecode.javacpp.Loader.load(Loader.java:372)
04-29 15:40:46.610: E/AndroidRuntime(23057): at com.googlecode.javacpp.Loader.load(Loader.java:319)
04-29 15:40:46.610: E/AndroidRuntime(23057): at com.googlecode.javacv.cpp.opencv_core.<clinit>(opencv_core.java:136)
04-29 15:40:46.610: E/AndroidRuntime(23057): ... 21 more
我已经满足了所有需要的要求,即 java SE 6、OpenCV 2.4.5、FFmpeg 1.2、Android NDK r8e。操作系统是 Ubuntu 11.10。
我认为代码不是问题,因为当我使用 javacv 中的捆绑库时它运行良好,但在我重建库以包含 x264 时遇到问题。
我究竟做错了什么?我已经尝试了 64 位和 32 位版本的 NDK,但同样的问题仍然存在。