Unrecognised Device in Linux
Saturday, 20th June 2015
I've been doing Android development almost exclusively on my laptop till now. That's because Android Studio on my desktop computer didn't recognise the Sony Xperia I'm using to test my app in development. When the laptop had the problem I updated Android Studio and that seemed to fix the problem. But an upgrade on the desktop didn't have the same result, so I had to dig further.
Typically when building and running the app, the device list would pop up with the only option showing "????????????" as the device name. Attempts at brute force running failed. In Windows, one can add device drivers for the phone, apparently, but this functionality isn't available for Linux. The steps I used to resolve the problem were these:
1. Update to the latest version of Android Studio if necessary, just because.
2. Check if the device is recognised with the command "adb devices", assuming that adb and all the other Android Studio stuff is in your path. If your device shows, then the upgrade has fixed the problem: stop here. Note that the name shown may not be recognisable; my Sony Xperia M2 Aqua showed up as "ZH8007716X" once I'd solved the problem.
3. Find out the vendor number of your device with "lsusb". You should get output that includes a line like this:
Bus 001 Device 004: ID 0fce:51b8 Sony Ericsson Mobile Communications AB
The "0fce" in that line is the vendor number.
4. Then you need to add the following line to the /etc/udev/rules.d/51-android.rules file. (in Ubuntu 14.04; it may be elsewhere in other distributions. Run "man udev" to find out where):
SUBSYSTEM=="usb", ATTR{idVendor}=="0fce", MODE="0666", GROUP="plugdev"
The "0fce" is for my Sony Xperia; for that substitute the relevant code output by the lsusb command.
5. Enter the following command to ensure the file has the right permissions:
sudo chmod a+r /etc/udev/rules.d/51-android.rules
6. Enter the following commands to restart udev and the adb service:
sudo service udev reload; sudo adb kill-server
7. Now you need to unplug and reconnect the device. After doing so, another "adb devices" command will restart adb and (hopefully) show the device as recognised.
8. The device will ask you to authorise the debug connection. Do this before trying to test any software on it.
9. Now build and test an app. If you don't have an app in known working condition, create the default Hello World app and try that out.
This is the second time I've managed to get the desktop machine to run something on the Sony Xperia. I can't remember what I did the first time around, but it obviously wasn't persistent. Hopefully this time I'll have more success. If not, at least I have the instructions here to do it all again!