Detect android device on linux

How do I get my device detected by ADB on Linux?

I just got my shiny new Wileyfox Swift – and before putting it to use I want to oem unlock and root it (as I usually do with new devices 😉 Trouble is, though usb-debugging is enabled on the device, and a corresponding line in /etc/udev/rules.d/51-android.rules exists, the device is not seen by adb devices . 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: How can I get my Android device seen and used by adb on Linux?

3 Answers 3

Enable USB debugging on the device

This is done in Settings › Development. If you don’t have that entry in your settings menu, go to Settings › About, scroll to the «Build number», and hammer it like a monkey until your device congratulates you having become a developer. Go back to the main page of the Settings menu, and close to the bottom you should see the «Development» (or «Developers») settings now. Enter it, and enable USB Debugging here.

Identify the device

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»:

Bus 004 Device 003: ID 2970:2282 

Setting up the rules for ADB

We now need the numbers at the end of the above line: 2970:2282 . These specify the vendor (2970) and the device itself (2282). Having those details, we need a root shell on our Linux machine to edit (or create, if it doesn’t yet exist) the /etc/udev/rules.d/51-android.rules file. In there, add a line for your device. Following example line shows how it looks for the Wileyfox Swift:¹

SUBSYSTEMS=="usb", ATTRS=="2970", ATTRS=="2282", MODE="0666", GROUP="androiddev", SYMLINK+="android%n" 

If you have a different device, replace the vendor and product IDs with what you’ve found above when running lsusb . A short explanation of the line:

  • SUBSYSTEMS==»usb» : obviously this rule is for USB only 😉
  • ATTRS==»2970″ : the vendor ID of the device this rule is for
  • ATTRS==»2282″ : the device ID
  • MODE=»0666″ : permissions the device node shall get. 0666 is quite lax, giving every user on your system read and write permission – so if you’re concerned, you might try replacing that with a 0660 (giving only owner and group read-write, and deny everything to others).
  • GROUP=»androiddev» : which group the device node should belong to. This should be a group the users intended to work with the device belong to.
  • SYMLINK+=»android%n» : just to give the node a nice name, so you can find it easier in /dev (in my case, it later showed up there as /dev/android5 )
Читайте также:  How to change hostnames in linux

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 .

Done that, leave the root shell. Disconnect and reconnect your Android device, try adb devices again. Most devices showed up now, but not the Wileyfox Swift – which obviously wants some extra cuddles. If you’re in that situation, open (or create if it doesn’t exist) the file ~/.android/adb_usb.ini and add a single line to it, naming the vendor you’ve found out with lsusb above; for the Swift that would be 0x2970 (yupp, here you need to prefix it by 0x to point out it’s a hexadecimal number). Then restart the ADB server: adb kill-server && adb start-server . Disconnect and reconnect the device again. Now adb devices should see it.

Connecting the device

You might have noticed adb devices told you something like 0123456789ABCDEF unauthorized . That’s OK and for your (devices) safety: your computer must be authorized first to be able to access the device. So simply issue adb shell now – which will be quit with an error: device unauthorized. Please check the confirmation dialog on your device. Follow that advice (optionally mark the check-box to permanently authorize your computer), and you’re done: Now you can use adb to access your device.

Updates:

¹ Note that in later Linux versions, syntax for the UDEV rules has slightly changed, as e.g. jcomeau_ictx pointed out in his comment. For the values we found above that would be:

SUBSYSTEM=="usb", ATTR=="2970", ATTR=="2282", MODE="0666", GROUP="plugdev", SYMLINK+="android%n" 

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).

Читайте также:  Exit status codes in linux

Additionally, you might need to add the vendorID to your ~/.android/adb_usb.ini (one ID per line, in hex notation):

# ANDROID 3RD PARTY USB VENDOR ID LIST # 1 USB VENDOR ID PER LINE. 0x2970 

Источник

Unknown Android Device — linux mint

then restart udev(shortcut); ./adb kill-server ; ./adb start-server , but still not work. Is this configuration correct for my system linux mint 11 and my phone sony ericsson xperia x10 ?? EDIT: Sorry i have LINUX MINT 12 (gnome 3?). I had wrong sys info in one file. Is it change anything ?

3 Answers 3

Under Linux Mint 11 I had to create the file /etc/udev/rules.d/51-android.rules and I added:

SUBSYSTEM=="usb", ATTR=="04e8", MODE="0666", GROUP="plugdev" SUBSYSTEM=="usb", ATTR=="04E8", MODE="0666", GROUP="plugdev" 

I used both upper and lower case because I was having lots of problems with 1 single entry in the rules file. The id 04E8 is for Samsung, use the right id for Sony Ericsson.

I restarted my laptop to make sure that all worked. This is overkill and restarting udev should be enough.

I am still a newbie to linux AND android development but I finally got my device recognized. The key (I THINK) was to change SUBSYSTEM to SUBSYSTEMS and ATTR to ATTRS. According to the udev(7) page, this «searches the devpath upwards for a matching device. » So, this is what I ended up doing for an HTC Incredible 2:

gksudo gedit /etc/udev/rules.d/51-android.rules 

Then I added this single line to the file

SUBSYSTEMS=="usb", ATTRS=="0bb4", MODE="0666", GROUP="plugdev" 

Then I restarted udev and adb (not sure if all of these are necessary). I also may have unplugged / plugged in my usb android connection (can’t remember):

sudo restart udev adb kill-server adb restart-server adb devices 

After this, the . went away from the adb devices results and instead I got something like HT14PMA. device

Читайте также:  Добавление корневых сертификатов linux

Like I said above, I’m a newbie and I’m not sure how much of what I did was necessary. I think the key may have been adding the «S» to SUBSYSTEMS to search multiple paths. It’s also possible I was doing other things wrong. Here’s the most helpful pages I found

EDIT: After getting the device recognized, I started eclipse (indigo) and successfully ran a «hello world» app on the connected phone. However subsequent to that I started getting problems connecting w/ eclipse (telling me it couldn’t find adb connection). So maybe my above advice is not sufficient and / or I have other problems. The adb connection problem in eclipse is intermittent, so clearly something is still not quite right.

Источник

Оцените статью
Adblock
detector