SDL2 for Android API level 19

SDL2 example application works without problem with newer Androids API 21+. The problem was with API level 19. It took me some time to figure out reasons for very interesting errors.

Let’s examine error messages and investigate how to fix them.

When I’ve started sdl2-android-example on a device with API 19, it failed with error message: dlopen failed: cannot locate symbol “signal” referenced by libSDL2.so”

The root cause is not that obvious from the error message. It failed because the application has been built for API 21 instead of API 19.

The fixture is easy, just set sdkVersion to 19.

For this purpose, I’ve extracted sdkVersion to settings.gradle which can be found in the root directory of the project.

Each module then has reference to this value:

Make complete clean and distributeLib to rebuild for proper API.

Hooray! Fixed. Let’s start the application.

Yey. New error: dlopen failed: could not load library “libSDL2_image.so” needed by “libmain.so”; caused by cannot locate symbol “png_set_longjmp_fn” referenced by “libSDL2_image.so”

The root cause of this issue is similar to the problem with JPEG described in the previous article. Paul Asiimwe found out that there is another library the name png and it has a different version so the application crashes.

To fix this issue it was necessary to rename whole png submodule to SDL2_png. Renaming requires clean and new distributeLib:

After these small tricks, the sdl2-android-example works even with API level 19.