How to passthrough USB in Android Studio emulator

I really, really would like to use and test my USB device through the emulator on android studio, and not have to resort to pluging it into a physical device.

There has to be a way to do this, I just can’t seem to find it. All I can find is a article for Android Automotive OS, https://source.android.com/docs/automotive/start/passthrough. But this does not seem to work. After running the emulator, I just get this, it’s like nothing happened, and my app does not detect the USB device.

`luispl@luispl:~/Android/Sdk/emulator$ ./emulator @Nexus_4_API_33 -no-snapshot -qemu -device usb-ehci,id=ehci -device usb-host,bus=ehci.0,vendorid=0x0483,productid=0x5740
INFO | Android emulator version 32.1.12.0 (build_id 9751036) (CL:N/A)
INFO | Found systemPath /home/luispl/Android/Sdk/system-images/android-33/google_apis/x86_64/
INFO | Storing crashdata in: /tmp/android-luispl/emu-crash.db, detection is enabled
INFO | Duplicate loglines will be removed, if you wish to see each indiviudal line launch with the -log-nofilter flag.
WARNING | cannot add library /home/luispl/Android/Sdk/emulator/qemu/linux-x86_64/lib64/vulkan/libvulkan.so: failed
INFO | added library /home/luispl/Android/Sdk/emulator/lib64/vulkan/libvulkan.so
INFO | Sending adb public key [QAAAAOl9huun1dmq2fDwmmup0rrlay3GmYhGm9WwCFUjCMaEhRE1GojLLeaXSXLzN45Xr+nzg882nwKIoUCG+Ue9pyWEBjCUo5KDQQSM5SqgZjmZuizJ0N283On8aeVaXFZKxtWf0/h6sQ1gxOets6M0X2YIy2QdoML8gOxfu5kybnZ41qefTNaq6vKhKQyPUYRjxng7KaFvn/8EvLEeTPvBJe9A4jERADD+CBCq02t2Jl8+m0ZQLYt0CEqv4k8+iANIYdTQJr7KOHPsRxAbOlnAstFSC3lrrF9xBkyeqhDX6EhS+bOoYic1E0lszboo701jsQvKRP5gbisCfMDGJJUJUqORRMHN5Rcvvdn+4nUTgJ3cOqozrrVQ2TQvrB+zQ7o9pa4GTbQZoSyd0gQ7+YWQgIn4Z2K4dzn5b061C8AYD05zSsEIkV+1KSshAiyDewFzBc5di+jV4b/v8Cv0r7G9llTW95HfrH1VeZfafIpqAiEbJJH2qTTlzFDc7u9maz2OB0qDl5VLlPfabBVz3S23GeDff+ChLLLTN7bvMqnBXUamqV4DpGYccCR/CxNWASsiwudYOUkSEf= luispl@unknown]
WARNING | *** No gRPC protection active, consider launching with the -grpc-use-jwt flag.***
INFO | Started GRPC server at 127.0.0.1:8554, security: Local, auth: none
INFO | Advertising in: /run/user/1000/avd/running/pid_188088.ini
INFO | Setting display: 0 configuration to: 768×1280, dpi: 320×320
INFO | Your emulator is out of date, please update by launching Android Studio:

  • Start Android Studio
  • Select menu “Tools > Android > SDK Manager”
  • Click “SDK Tools” tab
  • Check “Android Emulator” checkbox
  • Click “OK”
    INFO | Boot completed in 33342 ms
    INFO | Increasing screen off timeout, logcat buffer size to 2M.
    INFO | Revoking microphone permissions for Google App.`

I would really appreciate some help in trying to understand if this is possible. It is not common to want to emulate USB on android, but for me it is really important I am able to do this, my goal is to be able to run the app on PC as well as Android, without changing any code.

My app filters for the right pid and vid USB device, and upon connecting the USB device, it is supposed to show “Choose app for USB device”, but on the emulator, nothing.
Here is a bit of my code for detecting the USB device:

public UsbDevice getUsbDevice() { UsbManager manager = getUsbManager(); HashMap<String, UsbDevice> deviceList = manager.getDeviceList(); for (UsbDevice device : deviceList.values()) { if (device.getVendorId() == USB_VENDOR_ID && device.getProductId() == USB_PRODUCT_ID) { return device; } } return null; }

I also tried passing the port instead of the device.
This seems to be doing something now, but still some issues:

luispl@luispl:~/Desktop$ sudo ./run_emulator.sh -avd Nexus_4_API_33 -no-snapshot -qemu -device usb-ehci,id=ehci -device usb-host,bus=ehci.0,hostbus=1,hostport=7 INFO | Android emulator version 32.1.12.0 (build_id 9751036) (CL:N/A) INFO | Found systemPath /home/luispl/Android/Sdk/system-images/android-33/google_apis/x86_64/ INFO | Storing crashdata in: /tmp/android-luispl/emu-crash.db, detection is enabled INFO | Duplicate loglines will be removed, if you wish to see each indiviudal line launch with the -log-nofilter flag. WARNING | cannot add library /home/luispl/Android/Sdk/emulator/qemu/linux-x86_64/lib64/vulkan/libvulkan.so: failed INFO | added library /home/luispl/Android/Sdk/emulator/lib64/vulkan/libvulkan.so INFO | Sending adb public key [QAAAAOl9huun1dmq2fDwmmup0rrlay3GmYhGm9WwCFUjCMaEhRE1GojLLeaXSXLzN45Xr+nzg882nwKIoUCG+Ue9pyWEBjCUo5KDQQSM5SqgZjmZuizJ0N283On8aeVaXFZKxtWf0/h6sQ1gxOets6M0X2YIy2QdoML8gOxfu5kybnZ41qefTNaq6vKhKQyPUYRjxng7KaFvn/8EvLEeTPvBJe9A4jERADD+CBCq02t2Jl8+m0ZQLYt0CEqv4k8+iANIYdTQJr7KOHPsRxAbOlnAstFSC3lrrF9xBkyeqhDX6EhS+bOoYic1E0lszboo701jsQvKRP5gbisCfMDGJJUJUqORRMHN5Rcvvdn+4nUTgJ3cOqozrrVQ2TQvrB+zQ7o9pa4GTbQZoSyd0gQ7+YWQgIn4Z2K4dzn5b061C8AYD05zSsEIkV+1KSshAiyDewFzBc5di+jV4b/v8Cv0r7G9llTW95HfrH1VeZfafIpqAiEbJJH2qTTlzFDc7u9maz2OB0qDl5VLlPfabBVz3S23GeDff+ChLLLTN7bvMqnBXUamqV4DpGYccCR/CxNWASsiwudYOUkSEfZ7xmmKeRKQW3vhzJBU+XKXdzs2HdbsGgktJmm4wLGAsld16T+uFCjX/Y6C+XWUBIu6dCqwfneGgd/sH1+1rC7gdsD6AbcaTY/rWnKFegEAAQA= root@unknown] Home directory not accessible: Permission denied pulseaudio: pa_context_connect() failed pulseaudio: Reason: Connection refused pulseaudio: Failed to initialize PA contextCould not init pa’ audio driver
WARNING | *** No gRPC protection active, consider launching with the -grpc-use-jwt flag.***
INFO | Started GRPC server at 127.0.0.1:8554, security: Local, auth: none
WARNING | Using fallback path for the emulator registration directory.
INFO | Advertising in: /home/luispl/Android/Sdk/avd/running/pid_199112.ini
WARNING | Using fallback path for the emulator registration directory.
INFO | Setting display: 0 configuration to: 768×1280, dpi: 320×320
qemu-system-x86_64: Warning: speed mismatch trying to attach usb device “STM32 BOOTLOADER” (full speed) to bus “ehci.0”, port “1” (high speed)
qemu-system-x86_64: Warning: speed mismatch trying to attach usb device “STM32 BOOTLOADER” (full speed) to bus “ehci.0”, port “1” (high speed)
qemu-system-x86_64: Warning: speed mismatch trying to attach usb device “STM32 BOOTLOADER” (full speed) to bus “ehci.0”, port “1” (high speed)
INFO | Boot completed in 30070 ms
INFO | Increasing screen off timeout, logcat buffer size to 2M.
INFO | Revoking microphone permissions for Google App.
`

This log now shows “Warning: speed mismatch”.
What is more strange is that it seems to be picking up on the device, yet no Intents are lauched. Take a look at the logcat, when I plug in the device:

08-06 22:20:32.904 0 0 I usb 1-1 : new high-speed USB device number 7 using ehci-pci 08-06 22:20:33.085 0 0 I usb 1-1 : New USB device found, idVendor=0483, idProduct=5740, bcdDevice= 2.00 08-06 22:20:33.087 0 0 I usb 1-1 : New USB device strings: Mfr=1, Product=2, SerialNumber=3 08-06 22:20:33.101 0 0 I cdc_acm 1-1: 1.0: ttyACM0: USB ACM device

This is my device. So why does my app not pick up on anything? Why does the USB intent not get lauched?

New contributor

Luís Lopes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật