SDL2 Android instant-errors on startup

  1. I tried to use the SDL2 Android port and ran into this (tested
    on a real device):
    2.
    3. E/AndroidRuntime( 1608): FATAL EXCEPTION: main
    4. E/AndroidRuntime( 1608): java.lang.ExceptionInInitializerError
    5. E/AndroidRuntime( 1608): at
    java.lang.Class.newInstanceImpl(Native Method)
    6. E/AndroidRuntime( 1608): at java.lang.Class.newInstance(Class.java:1409)
    7. E/AndroidRuntime( 1608): at
    android.app.Instrumentation.newActivity(Instrumentation.java:1021)
    8. E/AndroidRuntime( 1608): at
    android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565)
    9. E/AndroidRuntime( 1608): at
    android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
    10. E/AndroidRuntime( 1608): at
    android.app.ActivityThread.access$1500(ActivityThread.java:117)
    11. E/AndroidRuntime( 1608): at
    android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
    12. E/AndroidRuntime( 1608): at
    android.os.Handler.dispatchMessage(Handler.java:99)
    13. E/AndroidRuntime( 1608): at android.os.Looper.loop(Looper.java:130)
    14. E/AndroidRuntime( 1608): at
    android.app.ActivityThread.main(ActivityThread.java:3691)
    15. E/AndroidRuntime( 1608): at
    java.lang.reflect.Method.invokeNative(Native Method)
    16. E/AndroidRuntime( 1608): at
    java.lang.reflect.Method.invoke(Method.java:507)
    17. E/AndroidRuntime( 1608): at
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
    18. E/AndroidRuntime( 1608): at
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
    19. E/AndroidRuntime( 1608): at
    dalvik.system.NativeStart.main(Native Method)
    20. E/AndroidRuntime( 1608): Caused by:
    java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1963]:
    132 could not load needed library ‘libstlport_shared.so’ for
    libSDL.so’ (load_library[1105]: Library ‘libstlport_shared.so’ not
    found)
    21. E/AndroidRuntime( 1608): at
    java.lang.Runtime.loadLibrary(Runtime.java:434)
    22. E/AndroidRuntime( 1608): at
    java.lang.System.loadLibrary(System.java:554)
    23. E/AndroidRuntime( 1608): at
    org.libsdl.app.SDLActivity.(SDLActivity.java:49)
    24. E/AndroidRuntime( 1608): … 15 more
    25. W/ActivityManager( 181): Force finishing activity
    org.libsdl.app/.SDLActivity

The offending line 49 in SDLActivity.java is:

    System.loadLibrary("SDL");

I use a recent hg SDL2 with
http://bugzilla.libsdl.org/show_bug.cgi?id=1308 manually applied (that
patch should really go into mainline btw!).

Other than that, I just use the stock SDL Android project with
build.xml regenerated (ant told me to do so with android update).

Can someone give me a hint what I should do from here? This is my
first Android dev experience, so I am not really familiar with the
SDK.

Regards,

Jonas Thiem

The offending line 49 in SDLActivity.java is:

    System.loadLibrary("SDL");

I use a recent hg SDL2 with
http://bugzilla.libsdl.org/show_bug.cgi?id=1308 manually applied (that
patch should really go into mainline btw!).

Other than that, I just use the stock SDL Android project with build.xml
regenerated (ant told me to do so with android update).

Can someone give me a hint what I should do from here? This is my first
Android dev experience, so I am not really familiar with the SDK.

Change SDL to SDL2 in all the loadLibrary lines in SDLActivity.java and you
should be good to go.

try to replace

System.loadLibrary(“SDL”);
with
System.loadLibrary(“SDL2”);

file a bugreport about it. the lib was renamed and the java sources
should get changed.Am 04.02.2012 09:21, schrieb Jonas Thiem:

  1. I tried to use the SDL2 Android port and ran into this (tested on
    a real device):
  2. E/AndroidRuntime( 1608): FATAL EXCEPTION: main
  3. E/AndroidRuntime( 1608): java.lang.ExceptionInInitializerError
  4. E/AndroidRuntime( 1608): at java.lang.Class.newInstanceImpl(Native
    Method)
  5. E/AndroidRuntime( 1608): at
    java.lang.Class.newInstance(Class.java:1409)
  6. E/AndroidRuntime( 1608): at
    android.app.Instrumentation.newActivity(Instrumentation.java:1021)
  7. E/AndroidRuntime( 1608): at
    android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565)
  8. E/AndroidRuntime( 1608): at
    android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
  9. E/AndroidRuntime( 1608): at
    android.app.ActivityThread.access$1500(ActivityThread.java:117)
  10. E/AndroidRuntime( 1608): at
    android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
  11. E/AndroidRuntime( 1608): at
    android.os.Handler.dispatchMessage(Handler.java:99)
  12. E/AndroidRuntime( 1608): at android.os.Looper.loop(Looper.java:130)
  13. E/AndroidRuntime( 1608): at
    android.app.ActivityThread.main(ActivityThread.java:3691)
  14. E/AndroidRuntime( 1608): at
    java.lang.reflect.Method.invokeNative(Native Method)
  15. E/AndroidRuntime( 1608): at
    java.lang.reflect.Method.invoke(Method.java:507)
  16. E/AndroidRuntime( 1608): at
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
  17. E/AndroidRuntime( 1608): at
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
  18. E/AndroidRuntime( 1608): at dalvik.system.NativeStart.main(Native
    Method)
  19. E/AndroidRuntime( 1608): Caused by:
    java.lang.UnsatisfiedLinkError: Cannot load library:
    link_image[1963]: 132 could not load needed library
    ’libstlport_shared.so’ for ‘libSDL.so’ (load_library[1105]:
    Library ‘libstlport_shared.so’ not found)
  20. E/AndroidRuntime( 1608): at
    java.lang.Runtime.loadLibrary(Runtime.java:434)
  21. E/AndroidRuntime( 1608): at
    java.lang.System.loadLibrary(System.java:554)
  22. E/AndroidRuntime( 1608): at
    org.libsdl.app.SDLActivity.(SDLActivity.java:49)
  23. E/AndroidRuntime( 1608): … 15 more
  24. W/ActivityManager( 181): Force finishing activity
    org.libsdl.app/.SDLActivity

The offending line 49 in SDLActivity.java is:

System.loadLibrary(“SDL”);

I use a recent hg SDL2 with
http://bugzilla.libsdl.org/show_bug.cgi?id=1308 manually applied (that
patch should really go into mainline btw!).

Other than that, I just use the stock SDL Android project with
build.xml regenerated (ant told me to do so with android update).

Can someone give me a hint what I should do from here? This is my
first Android dev experience, so I am not really familiar with the SDK.

Regards,

Jonas Thiem


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Updated, thanks!
http://hg.libsdl.org/SDL/rev/e3e5821999f1On Sat, Feb 4, 2012 at 11:55 AM, Gabriel Jacobo wrote:

The offending line 49 in SDLActivity.java is:

    System.loadLibrary("SDL");

I use a recent hg SDL2 with
http://bugzilla.libsdl.org/show_bug.cgi?id=1308 manually applied (that
patch should really go into mainline btw!).

Other than that, I just use the stock SDL Android project with build.xml
regenerated (ant told me to do so with android update).

Can someone give me a hint what I should do from here? This is my first
Android dev experience, so I am not really familiar with the SDK.

Change SDL to SDL2 in all the loadLibrary lines in SDLActivity.java and
you should be good to go.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

2012/2/5 Jonas Thiem :

Sadly, this doesn’t fix the issue.

Apparently, it fails due to libstlport_shared.so not being around which I pulled into the project for Box2D. However, that file is inside android-project/libs/armeabi/ like all other .so libs.

So why is Android unable to locate it?

I uploaded the whole Android project folder in case someone wants to have a look:

http://www.homeofjones.de/temp/android-project.zip

I realize this is more Android than SDL-related, but maybe someone has an idea what is going on.

When you ndk-build the project, do you see any errors? Did you inspect
the .apk file, is the .so file in there? Should you load it from
SDLActivity.java like the other .so files?–
Gabriel.

Try adding a file android-project/jni/Application.mk with the
following two lines:

APP_PROJECT_PATH := $(call my-dir)/…
APP_STL := stlport_sharedOn Tue, Feb 7, 2012 at 12:38 AM, Jonas Thiem wrote:

The ndk build goes fine. When extracting the .apk it does also definitely contain the libstlport_shared.so among the other libs.

Now, should I load it in SDLActivity? I have no idea, I am totally new to Android and the NDK. I am not using the lib directly though, it is just a dependency if that makes any difference.

Gabriel Jacobo wrote:

2012/2/5 Jonas Thiem :

Sadly, this doesn’t fix the issue.

Apparently, it fails due to libstlport_shared.so not being around
which I pulled into the project for Box2D. However, that file is inside
android-project/libs/armeabi/ like all other .so libs.

So why is Android unable to locate it?

I uploaded the whole Android project folder in case someone wants to
have a look:

http://www.homeofjones.de/temp/android-project.zip

I realize this is more Android than SDL-related, but maybe someone
has an idea what is going on.

When you ndk-build the project, do you see any errors? Did you inspect
the .apk file, is the .so file in there? Should you load it from
SDLActivity.java like the other .so files?


Gabriel.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

2012/2/8 Jonas Thiem :

I tried your suggestion with adding jni/Application.mk with the suggested contents. The resulting package:

http://www.homeofjones.de/temp/test.apk
(it can be renamed to .zip and unzipped, for the curious)

However, sadly the error remains. Same backtrace as before.

Regards,
Jonas Thiem

Did you try loading the library from the java file like the other libraries?–
Gabriel.

I did so before adding the Application.mk, and now tried again. I edited
android-project/src/org/libsdl/app/SDLActivity.java and added a loadLibrary
call for stlport_shared at line 49 before SDL2 is loaded.

However, same as before, it still wants to load SDL2 first for some weird
reason I do not understand and ends up with the same backtrace:

I think you need to break the dependency that libSDL2.so has on
libstlport_shared.so

objdump -x libSDL2.so | grep NEEDED
NEEDED libstlport_shared.so
NEEDED libdl.so
NEEDED libGLESv1_CM.so
NEEDED libGLESv2.so
NEEDED liblog.so
NEEDED libstdc++.so
NEEDED libm.so
NEEDED libc.sof

This dependency makes Android try to load libstlport_shared.so from
the SYSTEM paths along with the other system libraries, so it fails
(despite the fact that you are loading libstlport_shared by hand
previously, Android probably thinks this is a different library). I’ve
looked at your project files but I couldn’t figure out a simple way to
break this dependency, you’ll have to investigate further or perhaps
someone here already knows the answer.–
Gabriel.

Yes, this is very strange. SDL doesn’t depend on STL at all.On Wed, Feb 8, 2012 at 6:50 PM, Gabriel Jacobo wrote:

I did so before adding the Application.mk, and now tried again. I edited
android-project/src/org/libsdl/app/SDLActivity.java and added a
loadLibrary
call for stlport_shared at line 49 before SDL2 is loaded.

However, same as before, it still wants to load SDL2 first for some weird
reason I do not understand and ends up with the same backtrace:

I think you need to break the dependency that libSDL2.so has on
libstlport_shared.so

objdump -x libSDL2.so | grep NEEDED
NEEDED libstlport_shared.so
NEEDED libdl.so
NEEDED libGLESv1_CM.so
NEEDED libGLESv2.so
NEEDED liblog.so
NEEDED libstdc++.so
NEEDED libm.so
NEEDED libc.sof

This dependency makes Android try to load libstlport_shared.so from
the SYSTEM paths along with the other system libraries, so it fails
(despite the fact that you are loading libstlport_shared by hand
previously, Android probably thinks this is a different library). I’ve
looked at your project files but I couldn’t figure out a simple way to
break this dependency, you’ll have to investigate further or perhaps
someone here already knows the answer.


Gabriel.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

2012/2/8 Jonas Thiem :

Well I use Box2D which does depend on the STL.

It wouldn’t seem too unlikely to me that the Android SDK simply links all libs in the project against the STL once it is needed for 1+ contained libs.

However, why does the STL fail to load while it is obviously present as an .so file inside the .apk? I did not even compile and add that .so myself, the SDK has done this automatically for me. So why does it not work as a result?

You should read my previous email again, I’ve explained there why STL
fails to load even though it is in the apk. There’s something wrong in
your project .mk files that make the Android build tools think that
libSDL2.so depends on libstlport_shared.so . What the problem actually
is doesn’t seem obvious to me as I’m not familiar with the STL library
under Android.–
Gabriel.

Basically, I have no idea if that SDL->stl link is a problem, which .mk causes it and why it wants to load the system lib as you say, and why loadLibrary(“stlport_shared”) causes an SDL2 loading error with missing stlport_shared (which is what happens in one of my tests).
In short, I am still totally clueless.

What I said that I think is happening is:

loadLibrary(“stlport_shared”) -> works fine, but it doesn’t do any good.
loadLibrary(“SDL2”) -> loads libSDL2.so, which depends on
libstlport_shared.so BUT NOT THE ONE YOU JUST LOADED. The system
thinks it should be a library in the standard paths, and that’s why it
fails.

My suggestion would be to start by commenting out the APP_STL entries
in the .mk files, see what happens then. Or check with the source
(box2d?) of those other .mk files and ask them why it can be affecting
SDL in this manner.–
Gabriel.