Connecting USB devices to an Android emulator—such as external sensors, serial ports, or specialized USB hardware—is a notoriously tricky task. While the Android Emulator is powerful, by default, it does not easily pass through raw USB hardware from your host computer (Windows, macOS, or Linux).
Method 2: USBIP-Win (Best for Windows Hosts & Network Flexibility)
emulator -avd -qemu -usb -device usb-host,vendorid=0xXXXX,productid=0xYYYY Use code with caution. Replace XXXX and YYYY with your device's specific IDs. 2. Using Genymotion and VirtualBox
There are several methods for connecting USB devices to the Android Emulator, each with its own advantages and limitations. Here are a few:
emulator -avd Your_AVD_Name -qemu -usb -device usb-host,vendorid=0x1234,productid=0xabcd Use code with caution. Copied to clipboard Note: Replace 0x1234 and 0xabcd with your actual IDs. 2. Utilizing USB/IP for Windows (WSL & Remote) connect usb device to android emulator better
By default, the emulator may not possess the permission files required to allow apps to recognize USB devices as host-capable. You need to enable the USB Host API within the Android system image. Start Emulator with Write Access: emulator -avd YOUR_AVD_NAME -writable-system Use code with caution.
If your goal is to test an app on a device while that device is also using its USB port for a peripheral (like a flash drive or sensor), you cannot use a standard USB debug cable. Instead, use .
: High-speed devices, like USB webcams or external SSDs, can experience significant performance degradation when passed through. This is a known limitation of the QEMU/libusb implementation.
-qemu -device qemu-xhci -device usb-host,vendorid=0x1a2b,productid=0x3c4d Use code with caution. Connecting USB devices to an Android emulator—such as
If you develop apps using Windows Subsystem for Linux (WSL2) or require an isolated network-based USB bridge, the open-source usbipd-win project is highly reliable. Step 1: Install usbipd-win
Different architectures and operating systems present unique challenges:
adb shell dmesg | grep -i usb adb shell lsusb # if busybox is installed adb shell cat /sys/kernel/debug/usb/devices
Linux provides the most robust USB passthrough experience. The official Android documentation notes that “the Linux host must get access to the USB driver and then transfer it to QEMU”. However, you‘ll typically need sudo privileges to run emulators with USB passthrough: “Note that you have to use sudo in order to give exclusive access”. Replace XXXX and YYYY with your device's specific IDs
You must ensure no host applications, background daemons, or finder windows are actively communicating with the hardware before launching your pass-through scripts. On Linux, you may need to modify udev rules ( /etc/udev/rules.d/ ) to grant read/write permissions to your user account for that specific Vendor ID. 2. USB 3.0 vs. USB 2.0 Incompatibilities
./emulator -avd -qemu -device usb-ehci,id=usb -device usb-host,vendorid=0x ,productid=0x Use code with caution.
This reveals the port hierarchy: