This guide addresses how to install adb (Android Device Bridge) for Android Devices.
This guide is currently written using Ubuntu 11.10. It will be updated periodically for changes within the Android SDK and any changes the would accompany future Ubuntu releases.
This guide is directed for individuals interested in rooting their Android device or those interested in flashing custom ROMs, software development, or theme alterations or just about any other activity that would necessitate use of adb or fastboot for device modification.
1. Install the Android SDK and Download the Platform Tools Package from within the Android SDK Manager
Grab the Android SDK for linux: Google Android SDK
Place the file within your home directory.
Unpack the sdk within the your users home directory:
***Android-sdk version number may vary depending on version of the SDK downloaded.Code:cd ~ tar -zxvf android-sdk_r16-linux.tgz
Within the ~/android-sdk-linux/tools subfolder is an executable called android. Despite the non-descript name, the executable android is actually the Android SDK Manager. Launch the Android SDK Manager.
Select Android SDK Tools and Android SDK Platform-tools.(Screen shot provided below). Any additional packages may be downloaded as well. Go grab a bite to eat!!Code:./~/android-sdk-linux/tools/android
The platform tools package contains both the adb and fastboot executables. These programs will be located within the newly created directoy ~/android-sdk-linux/platform-tools
2. Modify your PATH environment variable to include the adb and fastboot executables.
The PATH environment variable may be either modified within ~/.profile (or ~/.bash_profile) or within ~/.bashrc. (The ~/.profile file is read upon login for all interactive shells, and the ~/.bashrc file is read upon all non-interactive shells (i.e sftp). In most cases and by default the ~/.profile file imports all settings from the ~/.bashrc file). The PATH statemnt must be altered to include the /android-sdk-linux/tools and /android-sdk-linux/platform-tools directories.
I modified my PATH statment within gedit by adding the following to the bottom of the ~/.bashrc file:
3. Create udev rules for Ubuntu to correctly identify the device when it is plugged into the USB portCode:export PATH=${PATH}:${HOME}/android-sdk-linux/tools:${HOME}/android-sdk-linux/platform-tools
This is the most difficult part of the entire process.
First plug in the device to the usb port, then execute the following command:
This should produce output similar to the following:Code:lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 063: ID 04e8:6860 Samsung Electronics Co., Ltd
In my working example, my device was correctly identified:
Bus 001 Device 063: ID 04e8:6860 Samsung Electronics Co., Ltd
The statement above can be deciphered:
Bus 001 Device 063: This information helps us determine the name of the device node. The device node's name is: /dev/bus/usb/001/063
04e8: The vendorID
6860: The productID
Using device node's name (/dev/bus/usb/001/063), its possible to query the device and discover its attributes. Discovery of these attributes is necessary since udev matches the device based on specific criteria. We need to right a ruleset that udev can use to match the device. The first step of this process is discovering criteria that can be plugged into our ruleset. This can be done in one of two ways, each are acceptable. The output of either of these methods generates the information for us to construct the udev rule for the device. The query program we are using for this method is known as udevadm
Query Method #1
In my particular situation, the name of my device node is: /dev/bus/usb/001/063, so hence my command would be:Code:udevadm info -q all -n <name of device node>
udevadm info -q all -n /dev/bus/usb/001/063
This gives output similar to the following:
$ udevadm info -q all -n /dev/bus/usb/001/063
P: /devices/pci0000:00/0000:00:1d.7/usb1/1-8
N: bus/usb/001/063
S: libmtp-1-8
S: GalaxyNexus
E: UDEV_LOG=3
E: DEVPATH=/devices/pci0000:00/0000:00:1d.7/usb1/1-8
E: MAJOR=189
E: MINOR=62
E: DEVNAME=/dev/bus/usb/001/063
E: DEVTYPE=usb_device
E: DRIVER=usb
E: PRODUCT=4e8/6860/216
E: TYPE=0/0/0
E: BUSNUM=001
E: DEVNUM=063
E: SUBSYSTEM=usb
E: ID_MTP_DEVICE=1
E: ID_MEDIA_PLAYER=samsung_galaxy-s2
E: ID_VENDOR=samsung
E: ID_VENDOR_ENC=samsung
E: ID_VENDOR_ID=04e8
E: ID_MODEL=Galaxy
E: ID_MODEL_ENC=Galaxy
E: ID_MODEL_ID=6860
E: ID_REVISION=0216
E: ID_SERIAL=samsung_Galaxy_0146B06501005018
E: ID_SERIAL_SHORT=0146B06501005018
E: ID_BUS=usb
E: ID_USB_INTERFACES=:ffff00:ff4201:
E: DEVLINKS=/dev/libmtp-1-8 /dev/GalaxyNexus
E: TAGS=:udev-acl:
Criteria that we will be using for matching are those lines starting with E: - E=ENV=Device Property value
Query Method #2
In my particular situation, the name of my device node is: /dev/bus/usb/001/063, so hence my command would be:Code:udevadm info -a -p $(udevadm info -q path -n <name of device node>)
udevadm info -a -p $(udevadm info -q path -n /dev/bus/usb/001/063)
This command gives output similar to:
$ udevadm info -a -p $(udevadm info -q path -n /dev/bus/usb/001/063)
Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.
looking at device '/devices/pci0000:00/0000:00:1d.7/usb1/1-8':
KERNEL=="1-8"
SUBSYSTEM=="usb"
DRIVER=="usb"
ATTR{configuration}==""
ATTR{bNumInterfaces}==" 2"
ATTR{bConfigurationValue}=="1"
ATTR{bmAttributes}=="80"
ATTR{bMaxPower}=="500mA"
ATTR{urbnum}=="29"
ATTR{idVendor}=="04e8"
ATTR{idProduct}=="6860"
ATTR{bcdDevice}=="0216"
ATTR{bDeviceClass}=="00"
ATTR{bDeviceSubClass}=="00"
ATTR{bDeviceProtocol}=="00"
ATTR{bNumConfigurations}=="1"
ATTR{bMaxPacketSize0}=="64"
ATTR{speed}=="480"
ATTR{busnum}=="1"
ATTR{devnum}=="63"
ATTR{devpath}=="8"
ATTR{version}==" 2.00"
ATTR{maxchild}=="0"
ATTR{quirks}=="0x0"
ATTR{avoid_reset_quirk}=="0"
ATTR{authorized}=="1"
ATTR{manufacturer}=="samsung"
ATTR{product}=="Galaxy"
ATTR{serial}=="0146B06501005018"
looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb1':
KERNELS=="usb1"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{configuration}==""
ATTRS{bNumInterfaces}==" 1"
ATTRS{bConfigurationValue}=="1"
ATTRS{bmAttributes}=="e0"
ATTRS{bMaxPower}==" 0mA"
ATTRS{urbnum}=="1403"
ATTRS{idVendor}=="1d6b"
ATTRS{idProduct}=="0002"
ATTRS{bcdDevice}=="0300"
ATTRS{bDeviceClass}=="09"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bDeviceProtocol}=="00"
ATTRS{bNumConfigurations}=="1"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{speed}=="480"
ATTRS{busnum}=="1"
ATTRS{devnum}=="1"
ATTRS{devpath}=="0"
ATTRS{version}==" 2.00"
ATTRS{maxchild}=="8"
ATTRS{quirks}=="0x0"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{authorized}=="1"
ATTRS{manufacturer}=="Linux 3.0.0-14-generic ehci_hcd"
ATTRS{product}=="EHCI Host Controller"
ATTRS{serial}=="0000:00:1d.7"
ATTRS{authorized_default}=="1"
looking at parent device '/devices/pci0000:00/0000:00:1d.7':
KERNELS=="0000:00:1d.7"
SUBSYSTEMS=="pci"
DRIVERS=="ehci_hcd"
ATTRS{vendor}=="0x8086"
ATTRS{device}=="0x27cc"
ATTRS{subsystem_vendor}=="0x103c"
ATTRS{subsystem_device}=="0x3010"
ATTRS{class}=="0x0c0320"
ATTRS{irq}=="20"
ATTRS{local_cpus}=="ff"
ATTRS{local_cpulist}=="0-7"
ATTRS{dma_mask_bits}=="32"
ATTRS{consistent_dma_mask_bits}=="32"
ATTRS{broken_parity_status}=="0"
ATTRS{msi_bus}==""
ATTRS{companion}==""
looking at parent device '/devices/pci0000:00':
KERNELS=="pci0000:00"
SUBSYSTEMS==""
DRIVERS==""
Criteria that we will be using for matching are those lines starting with ATTRS -- ATTRS-Device Attributes
Using either ENV or ATTRS, we can construct a ruleset for udev. Full information how to construct rules can be found here, I'll provide examples on how to use the criteria to construct the ruleset.
By arbitrary convention, the ruleset file will be called 51-android.rules.
The following are examples of rulesets that can be placed within the file (only one(1) ruleset is needed - Each should be only 1 line):Code:gksu gedit /etc/udev/rules.d/51-android.rules
SUBSYSTEM=="usb", ENV{ID_VENDOR_ID}=="04e8", ENV{ID_MODEL}=="Galaxy", MODE="0666", SYMLINK+="GalaxyNexus"
SUBSYSTEM=="usb", ENV{ID_VENDOR_ID}=="04e8", ENV{ID_MODEL_ID}=="6860", MODE="0666", SYMLINK+="GalaxyNexus"
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", ATTR{product}=="Galaxy" MODE="0666", SYMLINK+="GalaxyNexus"
As written above, these rules which listed matching criteria (SUBSYSTEM, ENV,ATTR) will only modify the mode of the device (0666=rw-rw-rw-) and create the symbolic GalaxyNexus link at /dev/GalaxyNexus. Additional actions however can be assigned to the device, such as activities to perform when the device is plugged in, or removed. These activites could be specified as follows:
ACTION=="add", RUN+="<name of action>"
ACTION==”remove”, RUN+="<name of action>"
**IMPORTANT**
.
- Each ACTION statement must be listed on its own line.
- The path to the program must be the full qualified path.
- There may also be multiple action lines or multiple add/remove statements
Example:
ACTION=="add", RUN+="/usr/local/bin/NexusMount.sh"
ACTION==”remove”, RUN+="/usr/local/bin/NexusUnmount.sh"
It would be possible for example to play a sound or .mp3 file when the device is inserted or ejected (similar to windows).
Once done constructing the rule, save the /etc/udev/rules.d/51-android.rules file.
Testing the ruleset
Its often a good idea to test the ruleset before executing it. Its very easy to make errors writing the ruleset so I would encourage this simple process to verify the ruleset is correct. This can be done using the udevadm tool.
The ruleset is the contents of the entire 51-android.rules file.Code:udevadm test --action=<"Copy entire ruleset here"> <path to device node>
The path to the device node can be discovered using:
udevadm info -q path -n d=<device name>
In the example above the name of my device was: /dev/bus/usb/001/063 (Which was discovered using the lsusb statement).
Putting this altogether as an example:
udevadm test --action="SUBSYSTEM=="usb", ENV{ID_VENDOR_ID}=="04e8", ENV{ID_MODEL}=="Galaxy" MODE="0666", SYMLINK+="GalaxyNexus"" $(udevadm info -q path -n /dev/bus/usb/001/063)
Although the output is rather long, two lines in the output correctly identify the ruleset actions are to be applied correctly:
udev_rules_apply_to_event: MODE 0666 /etc/udev/rules.d/51-android.rules:1
udev_rules_apply_to_event: LINK 'GalaxyNexus' /etc/udev/rules.d/51-android.rules:1
Once verifying the ruleset is correct, restart the udev service:
4. Log out and then log back into computer.Code:sudo service udev restart
With the device plugged in, adb should work similar to the following:
$ adb devices
List of devices attached
0146B06501005018 device
fastboot can also be ran, however this is only valid if the device has booted into fastboot mode:
$ fastboot devices
???????????? fastboot
***References
Bookmarks