Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Calling System.loadLibrary() causes process to die

I've decided to take on porting a game, that uses SDL libraries and makes heavy use of C++ and the STL, over to Android. I've been successful in getting all the required libraries compiled as well as all the source files for the game. My problem is that when I call System.loadLibrary() to load the .so for the game, the app immediately crashes with "Process org.libsdl.app (pid 3569) has died."

Here is the section of code where I load all the needed libraries and the game as a shared library.

    static {
       // Load the required libraries for the game
       System.loadLibrary("SDL");
       System.loadLibrary("SDL_image");
       System.loadLibrary("SDL_mixer");
       System.loadLibrary("SDL_net");
       // load the game as a shared library
       System.loadLibrary("smw_jni"); // << process dies when this is called
    }

libswm_jni.so was compiled with the Android NDK and in the Applicaion.mk file I specified

APP_STL := gnustl_static

Since it crashes immediately after System.loadLibrary("smw_jni") with no meaningful error messages, I am at a loss as to how to go about getting to the root cause.

I've worked on porting another game which was just plain old C code, which worked out, so I am not sure if there is an issue with the fact that this particular game is heavy on the C++ side.

Thanks in advance for any help with this headache of mine!

-clark-

like image 428
clark Avatar asked Sep 15 '11 19:09

clark


1 Answers

After pulling my hair out with this one I finally figured out the problem. It turns out one of the classes was performing some file IO on files that did not exist. In case someone else encounters a problem with loading a shared library, here is what I did to figure this one out.

I enabled a breakpoint at the call to System.loadLibrary() and when execution halted at this breakpoint, I then used stacktrace to get some extra information which was not being provided in logcat.

Since there was quite a bit of information I had stacktrace piped out to a file so I could analyze it. Here is the command I used

# adb shell strace -p pid > strace.log

I hope this helps anyone who comes across a similar pain in the arse problem.

-clark-

like image 62
clark Avatar answered Sep 17 '22 04:09

clark