Menu Bar

Friday, 10 October 2014

Setting up ADB On Ubuntu Linux

 

 

If you are like me and like developing in Linux, then you will find this guide useful. When I was setting up everything for my Android development, I ran into the problem that Linux was not recognizing my Android phone, and took me some time figuring out how to make Linux recognize my phone. Finally, after some research I was able to put this little guide together and decided to share it with the rest of the world.
ADB (Android Debug Bridge) is a handy tool that comes with Android SDK that allows you to control and interface with your Android device.

Update: 07/29/13 – In step 4, Android 4.2.x and up has Developer Options hidden. Added steps to make it visible
Update: 05/27/13 – Updated platform-tools (ADB) to latest version (Revision 17)
Update: 02/04/11 – HTC changed its Vendor ID, older phones have different ID than newer phones. Refer to USB Vendor IDs table at the bottom of this tutorial to see the change.
Update: 01/02/11 – By mistake I had linked the ADB tool for OSX in step 3.1. Now it should be the correct one for Linux.
IMPORTANT Update 12/11/10 – There has been a change to the new Android SDK. ADB Tool has been moved to /android-sdk-linux_x86/plataform-tools, so if you have the old SDK, please download the new one and update your path (Step 9.2 of this tutorial). If this is your first time doing this, then disregard the update and continue with the tutorial.
Update: 09/21/10 – Working code with Ubuntu Lucid Lynx and added more USB vendor IDs.
  1. Download the latest Android SDK from Google: Android SDK
  2. Extract the TGZ file to your home/YOUR-USERNAME directory
  3. To get ADB, you need to install the SDK: Installing the SDK
    • If you are not a developer and not planning to develop, then just download the following zip file containing only the ADB tool and proceed with the tutorial: ADB
  4. On your phone, click Settings > Applications > Development and make sure USB Debugging is on.
    • In Android 4.2.x and up Developer Options is hidden, to make it visible, do the following
    • Tap seven times in Build Number: Settings > About Phone > Build Number
    • You will get a message saying you have enabled Developer Options or something like that, go back to Settings and you will see Developer Options in there.
  5. Login as root and create this file: /etc/udev/rules.d/##-android.rules
    NOTE: In the above file replace ## with the number 50 if you are running Gusty/Hardy/Dapper (50-android.rules) or with the number 70 if you are running Karmic Koala/Lucid Lynx/Maverick Meerkat(70-android.rules)
    • Or simply type in terminal sudo gedit /etc/udev/rules.d/##-android.rules then enter your password
  6. The file should read:
    • For Gusty/Hardy: SUBSYSTEM==”usb”, SYSFS{idVendor}==”0bb4″, MODE=”0666″
    • For Dapper: SUBSYSTEM==”usb_device”, SYSFS{idVendor}==”0bb4″, MODE=”0666″
    • For Karmic Koala: SUBSYSTEM==”usb”, SYSFS{idVendor}==”0bb4″, MODE=”0666″
    • For Lucid Lynx: SUBSYSTEM==”usb”, SYSFS{idVendor}==”0bb4″, MODE=”0666″
    • For Maverick Meerkat: SUBSYSTEM==”usb”, ATTR{idVendor}==”0bb4″, MODE=”0666″
    NOTE: In the above lines the code ”0bb4″ refers to a HTC device. If your phone is from a different manufacturer, replace the code with the appropriate from the table below.
    NOTE: If you copy one of the lines mentioned above, make sure you replace the quotation marks with the ones in your keyboard, as these have different display code and it might give you a “no permissions” error.
  7. Execute: sudo chmod a+rx /etc/udev/rules.d/70-android.rules
  8. Reboot
  9. To run ADB you need to add an environment variable to your bashrc file:
    • Open a terminal window and type: sudo gedit .bashrc
    • Add the following line at the end: export PATH=${PATH}:/home/YOUR-USERNAME/android-sdk-linux_x86/platform-tools
    • Save and close
  10. You should be ready to go, type adb devices in a terminal window with your phone plugged in.
    If you see a serial number pop up that means you are done. Should look something like this:
    List of devices attached
    HT99PHF02521 device
  11. If for some reasons when running adb devices gives you a “no permissions” error, try typing the following in terminal
    • db kill-server
    • adb start-server
USB Vendor IDs
Manufacturer USB Vendor ID
Acer 0502
Dell 413c
Foxconn 0489
Garmin-Asus 091E
HTC (Older Phones) 0bb4
HTC (Newer phones) 18d1
Huawei 12d1
Kyocera 0482
LG 1004
Motorola 22b8
Nexus One/S 18d1
Nvidia 0955
Pantech 10A9
Samsung 04e8
Sharp 04dd
Sony Ericsson 0fce
ZTE 19D2

Common ADB Commands

– Lists which devices are currently attached to your computer
1adb devices
– Drops you into a basic linux command shell on your phone with no parameters, or lets you run commands directly
1adb shell
– Lets you install an Android application on your phone
1adb install
– Remounts your system in write mode – this lets you alter system files on your phone using ADB
1adb remount
– Rets you upload files to your phones filesystem
1adb push
– Lets you download files off your phones filesystem
1adb pull
– Starts dumping debugging information from your handset to the console – useful for debugging your apps
1adb logcat




------------------------------------------------------------------------------------------------------------------------------------

How to fix the adb no permissions error on Ubuntu Lucid

This blog post explains how to fix the no permissions error the Android Debugger displays when running the adb devices command Linux. The solutions presented here have been tested and found working on Ubuntu Lucid, but they should also work on other Ubuntu and Linux versions as well.
This official help center page has many working and non-working answers to the problem, and many comments. The root cause of the problem is that the current user doesn't have sufficient permissions to access the USB device file created when the phone was connected in USB debug mode.
Killing all running adb server instances with sudo killall adb, disconnecting the phone, reconnecting the phone, and then running sudo adb devices instead (so adb gets run as root) fixes the problem.
Alternatively, it is possible to implement a long-term fix which doesn't require sudo, thus it works with e.g. IntelliJ IDE integration:
  • Create a file named /tmp/android.rules with the following contents (hex vendor numbers were taken from the vendor list page):
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0bb4", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0e79", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0502", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0b05", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="413c", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0489", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="091e", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="18d1", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0bb4", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="12d1", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="24e3", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="2116", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0482", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="17ef", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="1004", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="22b8", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0409", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="2080", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0955", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="2257", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="10a9", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="1d4d", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0471", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="04da", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="05c6", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="1f53", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="04e8", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="04dd", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0fce", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0930", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="19d2", MODE="0666"
  • Run the following commands (without the leading $):
    $ sudo cp /tmp/android.rules /etc/udev/rules.d/51-android.rules
    $ sudo chmod 644   /etc/udev/rules.d/51-android.rules
    $ sudo chown root. /etc/udev/rules.d/51-android.rules
    $ sudo service udev restart
    $ sudo killall adb
  • Disconnect the USB cable between the phone and the computer.
  • Reconnect the phone.
  • Run adb devices to confirm that now it has permission to access the phone.
Please note that it's possible to use , USER="$LOGINNAME" instead of , MODE="0666" in the .rules file, substituting $LOGINNAME for your login name, i.e. what id -nu prints.

No comments:

Post a Comment

Tricks and Tips