Search code examples
androidandroid-ndkandroid-5.0-lollipoplibusb

Android L | libusb_init returns LIBUSB_ERROR_OTHER (-99)


I trying to use libusb on not rooted Nexus 5 as advised in this approach (by transferring usb file descriptor from java to native side).

My application ask permission via UsbManager.requestPermission and then run native method that call libusb_init to create libusb_context.

But libusb_init returns LIBUSB_ERROR_OTHER code (-99). After digging in the code I see why this happening. libusb reports 'could not find usbfs' because opendir("/dev/bus/usb") returns 0.

Also from adb shell I can't perform ls /dev, strange because I have rights (on Huawei U8950-1 with the same rights I can do this):

drwxr-xr-x root root 2014-09-04 10:26 dev

Looks like approach described below work not for all android devices. Can someone explain why?


Solution

  • There is already a fix in this libusb fork:

    https://github.com/martinmarinov/rtl_tcp_andro-

    Now, not only you will need to pass the file descriptor, you will need to pass the device file path as well via UsbDevice.getDeviceName().