问题描述
我设法修复以前的链接问题,我与NDK是由android api 21造成的,并设法得到SDL_TTF内置和工作轻松,但与SDL_Mixer我碰到另一个运行时Unsatisfiedlinkererror其中应用程序不知何故不能链接smpeg2 lib和SDL2_Mixer。这一次我不知道它可以与api级别有什么关系,并尝试了一切我可以想出来,通过每个makefile和三重检查每个版本。我使用SDL_Mixer 2.0.0和smpeg2-2.0.0作为它的唯一依赖。
我下载了SDL_Mixer 2.0.0源文件并将其放在jni /文件夹中,复制了smpeg2- 2.0.0从它的外部/文件夹到jni /和从混合器makefile设置只建立smpeg2。我编辑src / Android.mk查看混音器源,获取共享的lib,然后编辑SDLActivity拉SDL2_mixer库。 SDL_TTF以这种方式工作。
libsmpeg2.so存在于libs /文件夹中,因此我看不到它找不到它。
我使用android-19作为NDK的构建目标,编译器没有给出警告或错误。
01-22 18:17:43.760:D / dalvikvm(22101):尝试加载lib /data/data/com.kebabkeisari.peli/lib/libSDL2.so 0x41d88e78
01-22 18: 17:43.760:D / dalvikvm(22101):添加了共享lib /data/data/com.kebabkeisari.peli/lib/libSDL2.so 0x41d88e78
01-22 18:17:43.760:D / dalvikvm :尝试加载lib /data/data/com.kebabkeisari.peli/lib/libSDL2_mixer.so 0x41d88e78
01-22 18:17:43.765:W / dalvikvm(22101):异常Ljava / lang / UnsatisfiedLinkError;初始化Lorg / libsdl / app / SDLActivity时抛出;
01-22 18:17:43.765:W / dalvikvm(22101):newInstance调用中的类init失败(Lcom / kebabkeisari / peli / Ribale;)
01-22 18:17:43.765:D / AndroidRuntime(22101):关闭VM
01-22 18:17:43.765:W / dalvikvm(22101):threadid = 1:线程以未捕获异常退出(组= 0x410c52a0)
01-22 18:17:43.765:E / AndroidRuntime(22101):FATAL EXCEPTION:main
01-22 18:17:43.765:E / AndroidRuntime(22101):java.lang.ExceptionInInitializerError
01-22 18 :17:43.765:E / AndroidRuntime(22101):at java.lang.Class.newInstanceImpl(Native Method)
01-22 18:17:43.765:E / AndroidRuntime(22101):at java.lang.Class .newInstance(Class.java:1319)
01-22 18:17:43.765:E / AndroidRuntime(22101):在android.app.Instrumentation.newActivity(Instrumentation.java:1057)
01- 22 18:17:43.765:E / AndroidRuntime(22101):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2015)
01-22 18:17:43.765:E / AndroidRuntime android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
01-22 18:17:43.765:E / AndroidRuntime(22101):在android.app.ActivityThread.access $ 600(ActivityThread.java:140)
01-22 18:17:43.765:E / AndroidRuntime(22101):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1227)
01-22 18:17:43.765: E / AndroidRuntime(22101):在android.os.Handler.dispatchMessage(Handler.java:99)
01-22 18:17:43.765:E / AndroidRuntime(22101):在android.os.Looper.loop (Looper.java:137)
01-22 18:17:43.765:E / AndroidRuntime(22101):在android.app.ActivityThread.main(ActivityThread.java:4898)
01-22 18 :17:43.765:E / AndroidRuntime(22101):at java.lang.reflect.Method.invokeNative(Native Method)
01-22 18:17:43.765:E / AndroidRuntime(22101):at java.lang .reflect.Method.invoke(Method.java:511)
01-22 18:17:43.765:E / AndroidRuntime(22101):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit。 java:1006)
01-22 18:17:43.765:E / AndroidRuntime(22101):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
01-22 18:17:43.765:E / AndroidRuntime(22101):在dalvik.system.NativeStart.main(本地方法)
01-22 18:17:43.765:E / AndroidRuntime(22101):Caused by:java。 lang.UnsatisfiedLinkError:无法加载库:link_image [1892]:1952无法加载所需的库'libsmpeg2.so'为'libSDL2_mixer.so'(load_library [1094]:库'libsmpeg2.so'未找到)
01 -22 18:17:43.765:E / AndroidRuntime(22101):在java.lang.Runtime.loadLibrary(Runtime.java:370)
01-22 18:17:43.765:E / AndroidRuntime at java.lang.System.loadLibrary(System.java:535)
01-22 18:17:43.765:E / AndroidRuntime(22101):at org.libsdl.app.SDLActivity。< clinit>(SDLActivity .java:51)
01-22 18:17:43.765:E / AndroidRuntime(22101):...还有15个
您需要按照逆依赖顺序加载库。也就是说,如果 libSDL2_mixer.so
依赖于 libsmpeg2.so
,您首先需要加载 libsmpeg2.so
,然后才能尝试加载 libSDL2_mixer.so
。
,为了加载库,您需要这样做:
System.loadLibrary(smpeg2);
System.loadLibrary(SDL2_mixer);
IIRC在一些非常新版本的Android中已经修复,旧版本,您需要一次明确地加载一个。
I managed to fix the previous linking problem I had with NDK which was caused by android api 21, and managed to get SDL_TTF built and working easily, but with SDL_Mixer I bumped into another runtime Unsatisfiedlinkererror where the app somehow can't link smpeg2 lib with SDL2_Mixer. This time I don't see how it could have anything to do with api-level and have tried everything I could come up with, gone through every makefile and triple-checked every version.
I am using SDL_Mixer 2.0.0 and smpeg2-2.0.0 as its only dependecy. Smpeg2 is located in jni/ folder and the whole thing is built without compiler coughing.
I downloaded SDL_Mixer 2.0.0 source and put it in jni/ folder, copied smpeg2-2.0.0 from it's external/ folder to jni/ and set from mixer makefile to build only smpeg2. I edited src/Android.mk to see the mixer source and get the shared lib and then edited SDLActivity to pull SDL2_mixer library. SDL_TTF worked this way.
libsmpeg2.so DOES exist in libs/ folder so I don't see how it can't find it.
I am using android-19 as build target for NDK, no warnings or errors are given by the compiler.
01-22 18:17:43.760: D/dalvikvm(22101): Trying to load lib /data/data/com.kebabkeisari.peli/lib/libSDL2.so 0x41d88e78
01-22 18:17:43.760: D/dalvikvm(22101): Added shared lib /data/data/com.kebabkeisari.peli/lib/libSDL2.so 0x41d88e78
01-22 18:17:43.760: D/dalvikvm(22101): Trying to load lib /data/data/com.kebabkeisari.peli/lib/libSDL2_mixer.so 0x41d88e78
01-22 18:17:43.765: W/dalvikvm(22101): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lorg/libsdl/app/SDLActivity;
01-22 18:17:43.765: W/dalvikvm(22101): Class init failed in newInstance call (Lcom/kebabkeisari/peli/Ribale;)
01-22 18:17:43.765: D/AndroidRuntime(22101): Shutting down VM
01-22 18:17:43.765: W/dalvikvm(22101): threadid=1: thread exiting with uncaught exception (group=0x410c52a0)
01-22 18:17:43.765: E/AndroidRuntime(22101): FATAL EXCEPTION: main
01-22 18:17:43.765: E/AndroidRuntime(22101): java.lang.ExceptionInInitializerError
01-22 18:17:43.765: E/AndroidRuntime(22101): at java.lang.Class.newInstanceImpl(Native Method)
01-22 18:17:43.765: E/AndroidRuntime(22101): at java.lang.Class.newInstance(Class.java:1319)
01-22 18:17:43.765: E/AndroidRuntime(22101): at android.app.Instrumentation.newActivity(Instrumentation.java:1057)
01-22 18:17:43.765: E/AndroidRuntime(22101): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2015)
01-22 18:17:43.765: E/AndroidRuntime(22101): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
01-22 18:17:43.765: E/AndroidRuntime(22101): at android.app.ActivityThread.access$600(ActivityThread.java:140)
01-22 18:17:43.765: E/AndroidRuntime(22101): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
01-22 18:17:43.765: E/AndroidRuntime(22101): at android.os.Handler.dispatchMessage(Handler.java:99)
01-22 18:17:43.765: E/AndroidRuntime(22101): at android.os.Looper.loop(Looper.java:137)
01-22 18:17:43.765: E/AndroidRuntime(22101): at android.app.ActivityThread.main(ActivityThread.java:4898)
01-22 18:17:43.765: E/AndroidRuntime(22101): at java.lang.reflect.Method.invokeNative(Native Method)
01-22 18:17:43.765: E/AndroidRuntime(22101): at java.lang.reflect.Method.invoke(Method.java:511)
01-22 18:17:43.765: E/AndroidRuntime(22101): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
01-22 18:17:43.765: E/AndroidRuntime(22101): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
01-22 18:17:43.765: E/AndroidRuntime(22101): at dalvik.system.NativeStart.main(Native Method)
01-22 18:17:43.765: E/AndroidRuntime(22101): Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1892]: 1952 could not load needed library 'libsmpeg2.so' for 'libSDL2_mixer.so' (load_library[1094]: Library 'libsmpeg2.so' not found)
01-22 18:17:43.765: E/AndroidRuntime(22101): at java.lang.Runtime.loadLibrary(Runtime.java:370)
01-22 18:17:43.765: E/AndroidRuntime(22101): at java.lang.System.loadLibrary(System.java:535)
01-22 18:17:43.765: E/AndroidRuntime(22101): at org.libsdl.app.SDLActivity.<clinit>(SDLActivity.java:51)
01-22 18:17:43.765: E/AndroidRuntime(22101): ... 15 more
You need to load the libraries in reverse dependency order. That is, if libSDL2_mixer.so
depends on libsmpeg2.so
, you first need to load libsmpeg2.so
before you can try to load libSDL2_mixer.so
.
That is, in order to load the library, you need to do this:
System.loadLibrary("smpeg2");
System.loadLibrary("SDL2_mixer");
IIRC this has been fixed in some very recent version of Android, but in order to have things working on older versions, you need to explicitly load them one at a time.
这篇关于运行时链接错误与SDL_Mixer和Android上的SMPEG2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!