Thursday 15 January 2015

Enable detection of USB Devices on Ubuntu


You just connected your android device to the system to begin debugging and found nothing but ????? under the Devices window in your IDE. Now what ?

To get the device running on the Ubuntu we will need to register all the devices with a udev file which contains usb configuration for each device connecting to the system.
In the udev rules file each device manufacturer is identified by a unique vendor id as specified by ATTR{idVendor}.

Main steps :
1. Open terminal, assuming you are at home directory
    write command to change directory i.e. <cd ..> {without arrows} twice.
    Now change directory to <cd etc/udev/rules.d/> {without arrows}

2. Write command with root access to create a file
    $ sudo gedit 51-android.rules
    It will prompt for password : enter your system's root password
    It will create and open up the file with gedit (or you can use the editor of your choice too).

3. Now you will need to add entries corresponding to each device you are going to connect to your system.
And the format for those entries is as follows :
   SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev"
   where "0bb4" is the vendor id for HTC found along side more other manufacturers in the list at
   http://developer.android.com/tools/device.html#VendorIds

   Also the MODE assignment specifies read/write permissions, and GROUP defines which Unix group owns the device node.

4. Once you are done with the above step, close the gedit or the editor you were using to edit the file.

5. Now we will change the permissions for the new created rules file as follows:
  $ chmod a+r /etc/udev/rules.d/51-android.rules

Really! In what world ? 
  If in any case you had restarted your terminal just after editing the file and hence getting the Operation not permitted error for the above 5th step,
  then you got to run the above command with sudo at the first place and again entering password when prompted for.
  $ sudo chmod a+r /etc/udev/rules.d/51-android.rules

6. Once done, you are good to go to play with your device connected to your machine.


Connect your device with usb debugging ON to the machine. And here you are annoyed one more time by a prompt on the device to check the Allow USB debugging dialog box.
But don't worry this will be last time you will be bugged.

Here is the sample file 51-android.rules file containing most vendor details about most used devices in the world. If you didn't found your device, please match with the above given vendor id's
and add one for yours.

Above list contains vendor Id's for Samsung, Motorola, Sony, Google, LG, Lenovo, Acer, Asus, Intel, Huawei etc.