7 To build libusb for Android do the following:
9 1. Download the latest NDK from:
10 http://developer.android.com/tools/sdk/ndk/index.html
14 3. Open a shell and make sure there exist an NDK global variable
15 set to the directory where you extracted the NDK.
17 4. Change directory to libusb's "android/jni"
19 5. Run "$NDK/ndk-build".
21 The libusb library, examples and tests can then be found in:
24 Where $ARCH is one of:
35 If you wish to use libusb from native code in own Android application
36 then you should add the following line to your Android.mk file:
38 include $(PATH_TO_LIBUSB_SRC)/android/jni/libusb.mk
40 You will then need to add the following lines to the build
41 configuration for each native binary which uses libusb:
43 LOCAL_C_INCLUDES += $(LIBUSB_ROOT_ABS)
44 LOCAL_SHARED_LIBRARIES += libusb1.0
46 The Android build system will then correctly include libusb in the
47 application package (APK) file, provided ndk-build is invoked before
51 For a rooted device it is possible to install libusb into the system
52 image of a running device:
54 1. Enable ADB on the device.
56 2. Connect the device to a machine running ADB.
58 3. Execute the following commands on the machine
61 # Make the system partition writable
62 adb shell su -c "mount -o remount,rw /system"
65 adb push obj/local/armeabi/libusb1.0.so /sdcard/
66 adb shell su -c "cat > /system/lib/libusb1.0.so < /sdcard/libusb1.0.so"
67 adb shell rm /sdcard/libusb1.0.so
69 # Install the samples and tests
70 for B in listdevs fxload xusb sam3u_benchmark hotplugtest stress
72 adb push "obj/local/armeabi/$B" /sdcard/
73 adb shell su -c "cat > /system/bin/$B < /sdcard/$B"
74 adb shell su -c "chmod 0755 /system/bin/$B"
75 adb shell rm "/sdcard/$B"
78 # Make the system partition read only again
79 adb shell su -c "mount -o remount,ro /system"
82 adb shell su -c "listdevs"
84 4. If your device only has a single OTG port then ADB can generally
85 be switched to using Wifi with the following commands when connected
89 # Note the wifi IP address of the phone
91 # Use the IP address from netcfg
92 adb connect 192.168.1.123:5555
97 The default system configuration on most Android device will not allow
98 access to USB devices. There are several options for changing this.
100 If you have control of the system image then you can modify the
101 ueventd.rc used in the image to change the permissions on
102 /dev/bus/usb/*/*. If using this approach then it is advisable to
103 create a new Android permission to protect access to these files.
104 It is not advisable to give all applications read and write permissions
107 For rooted devices the code using libusb could be executed as root
108 using the "su" command. An alternative would be to use the "su" command
109 to change the permissions on the appropriate /dev/bus/usb/ files.
111 Users have reported success in using android.hardware.usb.UsbManager
112 to request permission to use the UsbDevice and then opening the
113 device. The difficulties in this method is that there is no guarantee
114 that it will continue to work in the future Android versions, it
115 requires invoking Java APIs and running code to match each
116 android.hardware.usb.UsbDevice to a libusb_device.