51-android.rules

0 views
Skip to first unread message

Sherry Galeazzi

unread,
Aug 3, 2024, 10:16:57 AM8/3/24
to demomona

if gedit is your editor of choice, from the command line write sudo gedit /etc/udev/rules.d/51-android.rules and add in the lines you want. There are plenty of examples but the main thing that will be individual to you is the vendor and product id found through a lsusb and looking at your device.

I know there are several answers scattered around this site, but they are either hard to find, just cover a specific device, or don't cover all steps I finally needed. So I take this as a chance for a canonical, device-independent question and give it a detailed answer below:

First we need to know how the device identifies on the USB bus. For that, with the Android device NOT connected, grab a shell and run the command lsusb. Then connect the device and run the command again. Spot the new line. For the Wileyfox Swift this is a "nameless device":

That rule entered in /etc/udev/rules.d/51-android.rules, we must tell udev to make use of it. Safest way (next to a reboot ;) is restarting the udev service. Depending on your Linux distro, this can be done either via sudo service udev restart or sudo /etc/init.d/udev restart.

Two differences: it's now SUBSYSTEM (no plural), and the group has changed from androiddev to plugdev (the former does not exist on recent systems, the latter does and usually is assigned at least to the first user).

Now connect the phone and run adb devices from the command line. You will probably see a device listed with "no permissions". This is fine.
IF it is not listed, you will have to add your device to the udev rules file, but for me, the tested devices just worked with the pre-defined rules.

Run adb shell and hopefully you will get a security notification on the phone asking if you want to trust the computer, select yes.
IF instead your computer says "error:insufficient permissions for device", you need to make sure that on the phone you have set your USB port to "Transfer files" mode, and not "Charge this device". On Android 8.1 this is located in settings under "Connected devices" > "USB".

I have noticed that even if you have everything working today, that tomorrow it may suddenly break for no apparent reason. If that happens, first check the USB port setting on the device, which may have changed back to charging mode, and if that fails, revoke USB debugging authorisations on the device (in settings under Developer options), and you should hopefully get the pop-up again when you run adb shell.

I have played around with USB packet sniffing with Wireshark and had used the modprobe usbmon module. When this module is loaded adb does not work anymore. In this case rmmod usbmonand adb kill-server helps.


This is a guide on how to enable a real on-device debugging for Qt applications on Android under Linux.I will show you how to achive this for Samsung device, but the same steps are required for any android device, you just have to know who is a vendor of your device.

2. Now make a rule 51-android.rules in the /etc/udev/rules.d/ directory. The number 51 is an information to udev so it can know in which order to load the rules. You can type some other number if you already had some rules defined, but keep in mind the order in which those rules will be applied.

If you take a closer look you will see that we used those bold numbers from step 2 so that we can make our rule apply only to our device. So the first string04e8 is an ID of a vendor of the device (in this case vendor is Samsung), and the second string 689e is the ID of the product (in this case product is a GT-S5670 which is a designation of Samsung Galaxy Ace mobile device). MODE="0666" just tells that the node that udev will create should be readable and writable by everyone.

c80f0f1006
Reply all
Reply to author
Forward
0 new messages