Android error libsdl2.so failed to load

when tested the app on galaxy 2 with android api 16 i get the following popup error

Error: Cannot load library:
link_image[1892]: 1853 could
not load needed library
‘libhidapi.so’ for ‘libSDL2.so’
(load_binary[1094]: Library
‘libhidapi.so’ no found)

on newer devices it works
the ibhidapi.so is in the apk
the build gradle in the android project state that min api is 14 so it should work?

Second that. I had to disable its loading in SDLActivity.java

So much trouble for frankly not so much functionality. Why it (hidapi) can’t be statically linked?

Same problem here.
I chose SDL2 version 2.0.8 and the problem is gone.

P.S. There was such a warning when building:

Android NDK: android-14 is unsupported. Using minimum supported version android-16.

I posted about this bug here:

https://bugzilla.libsdl.org/show_bug.cgi?id=4316

Can you guys chip-in with your latest experiences with this? I’m having the same problem on Android 4.2.2 (which is what Galaxy 2 runs if not updated?). This started when the new hidapi was introduced in SDL 2.0.9.

@lxnt can you tell what you disabled in SDLActivity.java?

  1. Disable compiling hidapi in SDL:
    include/SDL_config_android.h :
@@ -136,6 +136,7 @@
 /* Enable various input drivers */
  #define SDL_JOYSTICK_ANDROID    1
  #define SDL_JOYSTICK_HIDAPI    1
+ #undef SDL_JOYSTICK_HIDAPI
  #define SDL_HAPTIC_ANDROID    1

/* Enable sensor driver */

Then in SDLActivity.java :

        //mHIDDeviceManager = HIDDeviceManager.acquire(this);
        mHIDDeviceManager = null;

This is mostly due to android docs being horrible on how to make a gradle project without Android Studio (which is total shit in the face of even moderately sized C++ project) which would include multiple native dependencies (like SDL2, SDL2_mixer, SDL2_image and SDL_gfx with SDL2 patch) and put those dependencies’ libs and stuff where they belong.

And also SDL java glue throwing useless exceptions when hidapi can’t be loaded. That is a bug in SDL as far as I’m concerned.

:-/

Unfortunately that didn’t work for me. Still getting the error - but I might have made a mistake.

I’ve noticed a larger problem anyway. If you look at the new HID java files, they contain code that was introduced in API level 18. SDL2’s minimum API level is set to 16. Android 4.2.2 is API 17, so the hidapi stuff wasn’t going to ever work on Android 4.2 or below.

1 Like

I think I found a solution? Add this to your extended class (commenting out libs you don’t use of course):

@Override
protected String[] getLibraries() {
    return new String[]{
            "hidapi",
            "SDL2",
            // "SDL2_image",
            "SDL2_mixer",
            // "SDL2_net",
            // "SDL2_ttf",
            "main"
    };
}

Just in case you didn’t know, you can override this method so there’s no need to modify SDLActivity.java.

I wasted a whole day with this:
https://bugzilla.libsdl.org/show_bug.cgi?id=4601

1 Like

Hey Ant - can you tell me exactly where to put this code? I’m not that familiar with Java and not where my extended class is?

Also was this fixed in 2.0.10?

This looks to be fixed in 2.0.10. So if you can set up a working build with the new version this won’t be a problem.

If you use SDL_image, or _net or _ttf, you need to load them in getLibraries(). You can fudge SDLActivity.java directly, or the proper way is to override it in your own code. Just edit SDLActivity.java for now until you work out a better way. This is where you’d insert “hidapi”, but it’s already fixed now.