Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL HIDAPI Error error when running the 'Rectangles' example on Android #3242

SDLBugzilla opened this issue Feb 11, 2021 · 0 comments


Copy link

@SDLBugzilla SDLBugzilla commented Feb 11, 2021

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: 2.0.9
Reported for operating system, platform: Android (All), ARM

Comments on the original bug report:

On 2019-04-19 01:43:36 +0000, Steve Robinson wrote:

Created attachment 3753
Error screen shot

  1. Build SDL 2.0.9 with CMake for Android
  2. Build the 'Rectangles' example included in SDL2 source
  3. Run the APK

I get an 'SDL HIDAPI Error' when running the apk (see the attached screen shot).

Upon further investigation, it's clear that the newly-added hidapi functionality was not added to the CMake build system included with SDL2. The android-project/app/src/main/java/org/libsdl/app/ file used in the 'Rectangles' example is trying to load a hidapi shared library that doesn't exist.

So for users of CMake, SDL2 for Android is completely unusable and all other platforms do not include the new hidapi functionality.

On 2019-04-19 01:44:51 +0000, Steve Robinson wrote:

Created attachment 3754
Error screen shot

On 2019-04-19 01:46:47 +0000, Steve Robinson wrote:

Created attachment 3755
Error screen shot

On 2019-04-19 01:52:29 +0000, Steve Robinson wrote:

Created attachment 3756

On 2019-04-19 01:53:08 +0000, Steve Robinson wrote:

Created attachment 3757

On 2019-04-19 01:53:45 +0000, Steve Robinson wrote:

Created attachment 3758

On 2019-04-19 01:54:17 +0000, Steve Robinson wrote:

Created attachment 3759

On 2019-04-19 01:54:42 +0000, Steve Robinson wrote:

Created attachment 3760

On 2019-04-19 02:00:32 +0000, Steve Robinson wrote:

The work to add hidapi to the SDL2 CMake builds is here:
...and the key files have been attached to this bug.

Rename this file to CMakeLists.txt and put it in src/hidapi. It defines the hidapi static library. For linux, I chose the hidraw hid back-end instead of libusb since it supports USB and Bluetooth. More info:

When using CMake to build, set BUILD_SHARED_LIBS to ON to build hidapi as a shared library. Otherwise, it'll build as a static library.

The rest of the changes are defined in diff files from existing files from the 2.0.9 source zip. The file path is defined in the first line of each file.

This is a patch of the main SDL2 CMake file. This adds the joystick/hidapi/*.c files to SDL2 and references the CMake file that defines the hidapi build. There are also several build changes to allow a sample program to build and run with SDL2.

The code to load a hidapi shared library is removed since the SDL2 CMake file may be configured to build hidapi as a static library so loading the SDL2 library or a program that statically linked to the SDL2 library will be sufficient to load the hid native functions. Instead of an unhandled exception if the functions aren't found, I now log to logcat and continue.

Add SDL_JOYSTICK_HIDAPI so the appropriate code is included when this feature is enabled.


To test these changes, I took the rectangles example and built it with the above changes on Windows, Linux, Mac, iOS, and Android:

For all platforms except iOS you can download the built programs here:
Just click on the platform, then either 'Download' or 'Browse'.

I also used the patched SDL 2.0.9 in a closed source project.

I ran the programs on:
Windows 10 Pro ver. 1809
Ubuntu 16.04 LTS 64-bit
macOS High Sierra 10.13.6
Moto X Pure Edition (Android)
iPhone 4S

Programs loaded and ran fine.

On 2019-05-01 16:39:03 +0000, ZZ wrote:

It looks like that I have been bitten hard by this issue today on Shield TV/AS3.4. I don't use the standard app layout and because of various reasons it took me half a day until I found this bug report. Will this be committed to a working repository any time soon?

On 2019-08-24 09:57:57 +0000, ZZ wrote:

There is still no support for hidapi with CMake builds in 2.0.10 I guess?

On 2019-08-24 21:43:21 +0000, Steve Robinson wrote:

Yeah, I didn't try it out, but looking through the code it looks like it's still not fixed.

Hey SDL2 authors, please make CMake your only build system. It's the dominant build system for multiplatform C/C++ work. It already mostly works to build SDL2, just keep it up-to-date. If you still want to provide Xcode, make, and Visual Studio projects just use what CMake generates.

Also, while we're on the topic of best practices, using GitHub/GitLab and a CI would help formalize the collaboration process. I bet it would speed up development for you as well.

Build, CI, and dev workflows are my professional specialty. I'm happy to help out because I think SDL2 is fantastically useful. So hey, stop ignoring me and let's make this happen :)

On 2019-08-25 08:55:54 +0000, ZZ wrote:

Steve, this patches above have submitted them? Do you have any ideas why aren't there in?
Every time I try to upgrade SDL2 have to manually fix the build and everytime I don't remember anything and I am wasting time researching the causes.

This patch should disable hidapi (somewhat): spurious/SDL-mirror@79da113

I don't get why hidapi is necessary for Android and even if it is at all. And this README doesn't even state that it is supported on Android:

So I don't know even if I should bother.

On 2019-08-25 08:57:32 +0000, ZZ wrote:

On 2019-08-25 14:49:37 +0000, Sylvain wrote:

hidapi is not necessary for Android, since you can use the SDL android port without it.

I mean, if you have a patch to make sure sdl cmake compile on android with hiapi, I'll add it. I just haven't tried to do it.

On 2019-08-25 14:51:35 +0000, Sylvain wrote:

indeed building with cmake needs some attention... there are 30 open bugs with cmake keyword.

On 2019-08-25 18:44:53 +0000, ZZ wrote:


On 2020-04-19 08:06:12 +0000, Steve Robinson wrote:

CMake builds hidapi as of SDL 2.0.12 so I'm resolving this, thanks!

On 2020-07-09 15:59:42 +0000, ZZ wrote:

I don't see this happening on Android. Is there any trick?

On 2020-07-09 16:01:33 +0000, ZZ wrote:

Previously I used to do something like:

// Setup
protected void onCreate(Bundle savedInstanceState) {
    // In define:
    //   protected static boolean mHIDAPIEnabled = true;
    // In in:
    //   protected void onCreate(Bundle savedInstanceState)
    // modify:
    //   mHIDDeviceManager = HIDDeviceManager.acquire(this);
    // to:
    //   if (SDLActivity.mHIDAPIEnabled) {
    //        mHIDDeviceManager = HIDDeviceManager.acquire(this);
    //   }

    // Disable HIDAPI library usage
    SDLActivity.mHIDAPIEnabled = false;


On 2020-07-09 16:05:47 +0000, Steve Robinson wrote:

I resolved this bug months ago, it's fixed as of SDL 2.0.12.

On 2020-07-09 16:24:57 +0000, ZZ wrote:

Unfortunately I still get this:
about missing

I upgraded my sources to 2.0.12 recently.
And I don't see any in the apk.
I build all the libraries with gradle via Android Studio.

On 2020-07-09 16:28:58 +0000, ZZ wrote:

Is it fixed for CMake?

On 2020-07-09 17:36:51 +0000, ZZ wrote:

Thanx. I figured it out.

On 2020-07-16 02:33:32 +0000, Alexandre Tolstenko wrote:

(In reply to ZZ from comment # 21)

Unfortunately I still get this:
about missing

I upgraded my sources to 2.0.12 recently.
And I don't see any in the apk.
I build all the libraries with gradle via Android Studio.

Hey man, I am facing the same issues. I've tried the master branch and the 2.0.12, and I am facing the same problem. How did you solve it?

Btw I am using the cmake approach too without clues.

On 2020-07-16 04:30:39 +0000, Steve Robinson wrote:

You have to copy the alongside the or do what I did and change hidapi to a static lib in CMakeLists.txt:

..then remove the hidapi load command from

Here's my copy of the Rectangles example with the build files to make it all work:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

1 participant