From 679d3553170318ef690a920c7157e029206fcf05 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 1 Oct 2018 14:52:28 -0700 Subject: [PATCH] Fixed UnsatisfiedLinkError when initializing the HIDDeviceManager in some cases --- .../main/java/org/libsdl/app/HIDDeviceManager.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java index 8d29cf3645564..33ddb712059a0 100644 --- a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java +++ b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java @@ -80,6 +80,14 @@ public void onReceive(Context context, Intent intent) { public HIDDeviceManager(Context context) { mContext = context; + // Make sure we have the HIDAPI library loaded with the native functions + try { + System.loadLibrary("hidapi"); + } catch (Exception e) { + Log.w(TAG, "Couldn't load hidapi: " + e.toString()); + return; + } + HIDDeviceRegisterCallback(this); mSharedPreferences = mContext.getSharedPreferences("hidapi", Context.MODE_PRIVATE); @@ -180,7 +188,11 @@ UsbManager getUSBManager() { } protected void shutdownUSB() { - mContext.unregisterReceiver(mUsbBroadcast); + try { + mContext.unregisterReceiver(mUsbBroadcast); + } catch (Exception e) { + // We may not have registered, that's okay + } } protected boolean isHIDDeviceUSB(UsbDevice usbDevice) {