Runtime linking error with SDL_Mixer and SMPEG2 on Android

风格不统一 提交于 2019-12-25 04:42:32

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/28093953/runtime-linking-error-with-sdl-mixer-and-smpeg2-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!