Introduction
This guide will help you maintain a stable ADB connection between multiple Android devices and a Docker container running on an Ubuntu server. This setup is essential for developers who need to test applications on several devices simultaneously in a containerized environment. We will cover how to configure udev
` rules, set up the ADB server, and ensure reliable communication between devices and the container. By following these steps, you will have a robust setup for managing multiple ADB connections in a Docker environment, even when multiple users are working on the server.
Solution
1. Allow only the user(s) in plugdev
group to have access to the devices
- Get vender id and produce id from the output of the
lsusb
command.$ lsusb Bus 007 Device 005: ID 04e8:6860 Samsung Electronics Co., Ltd Galaxy A5 (MTP) Bus 005 Device 009: ID 04e8:6860 Samsung Electronics Co., Ltd Galaxy A5 (MTP) Bus 001 Device 003: ID 04e8:6860 Samsung Electronics Co., Ltd Galaxy A5 (MTP)
- Create the Android
udev
rules file and add the following line to it.$ sudo vi /etc/udev/rules.d/51-android.rules SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0666", GROUP="plugdev"
- Add the user to the
plugdev
group$ sudo usermod -aG plugdev [USERNAME]
2. Disable Ubuntu’s USB power saving
- Temporarily disable USB power saving:
echo -1 > /sys/module/usbcore/parameters/autosuspend`
- Permanently disable USB power saving:
# add `usbcore.autosuspend=-1` option at the end of `GRUB_CMDLINE_LINUX_DEFAULT` option in `/etc/default/grub` $ sudo /etc/default/grub GRUB_CMDLINE_LINUX_DEFAULT="quiet splash usbcore.autosuspend=-1" $ sudo update-grub
3. Reboot the server & run docker container with previledge and mounted android devices.
- Kill local ADB server
$ adb kill-server
- Run the Docker container with privileged access and mount the Android devices:
$ docker run -it --rm --privileged -v /dev/bus/usb:/dev/bus/usb --name [container_name] [image_name] /usr/bin/zsh $ adb devices
References
- adb devices => no permissions (user in plugdev group; are your udev rules wrong?) [duplicate]
- user in plugdev group; are your udev rules wrong or error: insufficient permissions for device: udev requires plugdev group membership?
- Are all of your usb devices disconnecting periodically, for seemingly no reason? Here’s the fix
- Connecting to a USB Android device in a Docker container via ADB
Leave a comment