7

I'd like to use libusb in my Android app (java GUI + native(C++) core). I have already compiled libusb and tried calling its functions, but libusb_open return LIBUSB_ERROR_ACCESS. I suppose there is a problem with USB access permissions, but I don't know how to resolve the issue. So, 2 questions here: 1) How to get libusb running on a rooted Android 3.1 device? 2) Is it possible to use libusb on an unrooted, factory-default device?

Thanks in advance.

P. S. As for question 1, I've tried chmod 666 for /dev/bus/usb, but it says "permission denied" (note that my device IS rooted).

P.P.S. mount usbfs none /proc/bus/usb -o devmode=0666 doesn't even execute, as if I have misspeled something (but I didn't).


I know for sure it's possible to get libusb working on a rooted Android device with USB host, but I never managed it, so I had to restrict the app to Android 3.1+ and use USB APIs.

Violet Giraffe
  • 32,368
  • 48
  • 194
  • 335
  • As you apparently are working with Android 3.1, have you considered using the [USB APIs](http://developer.android.com/guide/topics/usb/index.html) in the Android SDK? – Frxstrem Feb 09 '12 at 22:52
  • @Frxstrem: yes, I had to resort to that solution. I'm not quite happy with it, but it works and it's the standard way of using USB on Android, so I guess I should close the question. – Violet Giraffe Feb 10 '12 at 11:48
  • 2
    don't close it, just answer it. – m-ric Sep 20 '12 at 03:36
  • Have you tried ``sudo chmod 666`` for /dev/bus/usb? – Sergey K. Jul 03 '13 at 14:54
  • @SergeyK.: I believe I did. but can't say for sure. I gave up on using `libusb` and just utilized standard Android USB API, which is the right way to go anyway. – Violet Giraffe Jul 03 '13 at 15:19
  • Thanks for the update. It would be great if you can summaries your achievements and recommendations here as the answer! – Sergey K. Jul 03 '13 at 15:20

1 Answers1

1

In android, you cannot directly open usb device using libusb (this is the conclusion that you came to :).

why you were not able to open?

You need to get permission from Android system (!= Kernel) to open a device.

Do it in Java:

when you request, a pop is shown to user to accept or reject. so you need to open the device in java, and extract the fd using java and pass on to libusb so that it can communicate with device.

now how will libusb build a handle from fd?

Update: I maintain a libusb version specific modified for Android (with more fixes - tested/working on Android 5.1 and lower). see https://gitlab.com/madresistor/libusb/blob/android/README

OLD LINK (DEAD LINK) here the solution: https://github.com/martinmarinov/rtl_tcp_andro-/blob/master/jni/libusb-andro/libusb/core.c#L993

Kuldeep Dhaka
  • 533
  • 5
  • 22