All the way back in 2010 I wrote a post how to connect your Android device to your Ubuntu computer in order to develop on it. There have been a few changes since then, so here is the updated version of that post.

Recently, out of the blue I had permission issues accessing the my phone via adb. When I ran “adb devices” I got a “no permissions” message:

$ adb devices
List of devices attached
8XV7N18328713317	no permissions (verify udev rules); see [http://developer.android.com/tools/device.html]

It gives you a link to a Google article that addresses the issue, but their solution did not work for me.

So, here are the steps you need to take to be able to connect your Android device:

  1. Enable Unknown sources and USB debugging on your device
  2. Settings -> Developer Options -> USB debugging
    Settings -> Security -> Unknown sources

    The unknown sources in needed only if you will be developing on your device and you will be installing dev apk files.

  3. Find out the vendor id and product id of your device
  4. Run “lsusb”. This will list all of the devices connected to the USB ports of your computer- mouse, keyboard, camera, etc. including your phone or tablet. Each device will have a description, so it will be easy to identify.

    In my case the phone is a Nexus 6P, identified here as a Google device:

    $ lsusb
    Bus 002 Device 008: ID 18d1:4ee7 Google Inc. 

    This device is number 008 on bus number 002.

    You can see the device object created by udev. It is a fileL /dev/bus/usb//
    In this case it would be: /dev/bus/usb/002/008

    18d1:4ee7 represents VendorID:ProductID. In this case the vendor id is 18d1 and the product id is 4ee7. The vendor id and product id are different for each device manufacturer.

  5. Set up udev rules
  6. Now that we have all the info we need, we can set up the rules.

    Create a 51-android.rules file in /etc/udev/rules.d

    $ sudo gedit /etc/udev/rules.d/51-android.rules

    In this file you should create a rule for each device you want to connect.

    ATTR{idProduct}=="4ee7", SYMLINK+="android_adb", MODE="0660", GROUP="plugdev", TAG+="uaccess", SYMLINK+="android"

    Here, replace “4ee7” with your device’s product id from step #2.

    Note the GROUP=”plugdev” entry. This will create the device object file with the plugdev group as an owner. You need to make sure that your user is part of this group. This is done in the next step.

  7. Add your user to the plugdev group
  8. sudo usermod -a -G plugdev $(id -u -n)
  9. Activate the new udev rule and restart adb
  10. $ sudo udevadm control --reload-rules
    $ sudo service udev restart
    $ sudo udevadm trigger
    

    Now if we list the object files we should see that our device has a group of plugdev:

    $ ls -l /dev/bus/usb/002/
    total 0
    crw-rw----+ 1 root plugdev 189, 135 May  7 21:48 008

    Also, we should have two symlinks in /dev pointing to our device object:

    $ ll /dev | grep android
    lrwxrwxrwx   1 root root          15 May  7 21:48 android -> bus/usb/002/008
    lrwxrwxrwx   1 root root          15 May  7 21:48 android_adb -> bus/usb/002/008
  11. Restart adb and check the result
  12. $ adb kill-server
    $ adb start-server
    * daemon not running. starting it now at tcp:5037 *
    * daemon started successfully *
    $ adb devices
    List of devices attached
    8XV7N18328713317	device

    As you can see, we now have access to the connected device and can begin work.

I found a github project where the community is maintaining a rules file with the most widely used Android devices. You can just copy this rules file:
https://github.com/M0Rf30/android-udev-rules/blob/master/51-android.rules

Make sure to change the group from adbusers to plugdev. The line is towards the end of the file. GROUP=”adbusers” should be changed to GROUP=”plugdev”.

Then do steps 4, 5 and 6 above.

How to connect your Android phone to Ubuntu to do development, testing, installations or tethering – Updated

2 thoughts on “How to connect your Android phone to Ubuntu to do development, testing, installations or tethering – Updated

  • April 3, 2018 at 3:02 am
    Permalink

    Thanks for the post. It really solved my problem on Unbutu machine.

  • March 28, 2019 at 6:27 pm
    Permalink

    Thanks it worked!

Leave a Reply

Your email address will not be published. Required fields are marked *

*