How to Connect an Android Phone to Ubuntu to Access System and Files on Android? (English)
How to connect an Android phone to Ubuntu to access system and files on Android?¶
Introduction
If you want to connect your Android phone to Ubuntu to do development, testing, manipulating files or just fun. You could be following these methods.
If you want to develop Android software in Ubuntu. Firstly, you need to connect your Android phone to Ubuntu and you may encounter no permissions to access your Android phone. There is a way to help you correctly connection.
Commonly, We often connect the Android phone to the computer through USB port and run 'adb devices'. However, you may will find out that it is not recognized, such as below:
$ ./adb devices List of devices attached ???????????? no permissions
If you encounter this problem, don't worry, it is easily repairable in Ubuntu. You just edit a file and then you should be good to go.
Equipment
Operation System: Ubuntu 14.04 LTS
Mobile Phone: HTC incredible S (htc_vivo)
Usage
- To find out the Vendor ID number and Product ID number.
Your Ubuntu can not recognize your Android phone, because it have not the manufacturer and model of the device. Now, you are able to find out it through by this command-line 'lsusb' when you connected it via USB of course.
$ lsusb Bus 001 Device 003: ID 0fce:51a3 Sony Ericsson Mobile Communications AB Bus 002 Device 005: ID 093a:2521 Pixart Imaging, Inc. … (More)
In this case, the vendor ID number is '0fce' and the Product ID number is '51a3'.
Please keep the two numbers in your note, you will use them.
- To create or edit a rule file of USB device in Ubuntu.
$ cd /etc/udev/rules.d $ ls -l 51-android.rules 99-android.rules
If you want to create or edit them. Please remember to use 'sudo' command-line, because the directory (/etc/udev/rules.d) of the owner is root. There are some examples for you.
$ sudo gedit /etc/udev/rules.d/10-android.rules $ sudo gedit /etc/udev/rules.d/51-android.rules $ sudo gedit /etc/udev/rules.d/91-android.rules $ sudo gedit /etc/udev/rules.d/99-android.rules
If you can not find out it, you should refer to your note and fill blank the line as below.
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”(Vendor ID)″, ATTRS{idProduct}==”(Product ID)″, MODE=”0666″
Otherwise, you can reference to my rules files as below.
File name: /etc/udev/rules.d/51-android.rules
# adb protocol on passion (Nexus One)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e12", MODE="0600", OWNER="(Your Login Account Name)"
# fastboot protocol on passion (Nexus One)
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="0fff", MODE="0600", OWNER="(Your Login Account Name)"
# adb protocol on crespo/crespo4g (Nexus S)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e22", MODE="0600", OWNER="(Your Login Account Name)"
# fastboot protocol on crespo/crespo4g (Nexus S)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e20", MODE="0600", OWNER="(Your Login Account Name)"
# adb protocol on stingray/wingray (Xoom)
SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", ATTR{idProduct}=="70a9", MODE="0600", OWNER="(Your Login Account Name)"
# fastboot protocol on stingray/wingray (Xoom)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="708c", MODE="0600", OWNER="(Your Login Account Name)"
# adb protocol on maguro/toro (Galaxy Nexus)
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0600", OWNER="(Your Login Account Name)"
# fastboot protocol on maguro/toro (Galaxy Nexus)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e30", MODE="0600", OWNER="(Your Login Account Name)"
# adb protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d101", MODE="0600", OWNER="(Your Login Account Name)"
# adb protocol on panda (PandaBoard ES)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="d002", MODE="0600", OWNER="(Your Login Account Name)"
# fastboot protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d022", MODE="0600", OWNER="(Your Login Account Name)"
# usbboot protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d00f", MODE="0600", OWNER="(Your Login Account Name)"
# usbboot protocol on panda (PandaBoard ES)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d010", MODE="0600", OWNER="(Your Login Account Name)"
# adb protocol on grouper/tilapia (Nexus 7)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e42", MODE="0600", OWNER="(Your Login Account Name)"
# fastboot protocol on grouper/tilapia (Nexus 7)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e40", MODE="0600", OWNER="(Your Login Account Name)"
# adb protocol on manta (Nexus 10)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee2", MODE="0600", OWNER="(Your Login Account Name)"
# fastboot protocol on manta (Nexus 10)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee0", MODE="0600", OWNER="(Your Login Account Name)"
# adb protocol on Sony Ericsson Mobile Communications AB C2304
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”0bb4″, ATTRS{idProduct}==”18d1″, MODE=”0666″, OWNER="(Your Login Account Name)"
# HTC G1
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”0bb4″, ATTRS{idProduct}==”0c01″, MODE=”0666″
# HTC Hero
UBSYSTEMS==”usb”, ATTRS{idVendor}==”0bb4″, ATTRS{idProduct}==”0c02″, MODE=”0666″
# HTC EVO
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”0bb4″, ATTRS{idProduct}==”0c8d”, MODE=”0666″
# HTC EVO Shift
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”0bb4″, ATTRS{idProduct}==”0ca5″, MODE=”0666″
# HTC ThunderBolt
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”0bb4″, ATTRS{idProduct}==”0ca4″, MODE=”0666″
# LG OPTIMUS LG-P506
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”1004″, ATTRS{idProduct}==”618e”, MODE=”0666″
# Motorola Xoom
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”22b8″, ATTRS{idProduct}==”70a9″, MODE=”0666″
# Samsung Galaxy S II I9100
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”04e8”, ATTRS{idProduct}==685e”, MODE=”0666”
# Samsung Nexus S
SUBSYSTEMS==”usb”, ATTR{idVendor}==”18d1”, ATTR{idProduct}==”4e22”, MODE=”0666”
# Samsung Galaxy S2
SUBSYSTEMS==”usb”, SYSFS{idVendor}==04e8, SYSFS{idProduct}==”685e”, MODE=”0666”, OWNER=”(your login account name)”, GROUP=”plugdev”
# Motorola Droid 3
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”22b8”, ATTRS{idProduct}==”41db”, MODE=”0666”
# General Mobile Discovery 16 GB
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”0bb4”, ATTRS{idProduct}==|0c03”, MODE=”0666”
File name: /etc/udev/rules.d/10-motorola-droid.rules
# Motorola Droid
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”22b8″, ATTRS{idProduct} ==”41db”, MODE=”0600″
File name: /etc/udev/rules.d/99-android.rules
# Nexus One
SUBSYSTEM==”usb”, ATTRS{idVendor}==”18d1″, SYMLINK+=”android_adb”, MODE=”0666″
# HTC incredible S
SUBSYSTEM=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0cac", MODE="0666"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0cac"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0fce", ATTRS{idProduct}=="51a3", MODE="0666"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0fce", ATTRS{idProduct}=="51a3"
TEST=="/var/run/ConsoleKit/database", \
RUN+="udev-acl --action=$env{ACTION} –device=$env{DEVNAME}"
File name: /etc/udev/rules.d/91-android.rules
# Samsung Galaxy
SUBSYSTEM==”usb”,ATTRS{idVendor}==”04e8”, SYMLINK+=”android_adb”, MODE=”0666”, OWNER="(Your Login Account Name)"
# GPAD G10 4 Gig
SUBSYSTEM==”usb”,ATTRS{idVendor}==”18d1”, SYMLINK+=”android_adb”, MODE=”0666”, OWNER="(Your Login Account Name)"
You need to change attributes of those files.
$ sudo chmod a+rx /etc/udev/rules.d/10-android.rules $ sudo chmod a+rx /etc/udev/rules.d/51-android.rules $ sudo chmod a+rx /etc/udev/rules.d/91-android.rules $ sudo chmod a+rx /etc/udev/rules.d/99-android.rules
- To enable 'Unknown sources' and 'USB debugging' in your Android phone.
3.1. Go to 'Settings'
3.2. If you have not to see 'development/developer options', you should go to 'About phone' to find out 'Build number' and then tap it seven times. Go back 'Settings', you would be able to see it.
3.3. Go to 'Development' and enable the USB debugging.
3.4. Go to 'Applications' and check the 'Unknown sources' check-box.
- Restart 'udev' in Ubuntu.
You need to use 'sudo' command-line, because 'restart udev' can not run.
In my opinion, I think you should be to stop and start the 'adb server'.
$ sudo restart udev $ ./adb kill-server $ ./adb start-server $ ./adb devices List of devices attached SH24SW123456 device
You are also running this command-line as below.
$ sudo /etc/init.d/udev restart
$ sudo ./(your adb path)/platform-tools/adb kill-server
$ sudo ./(your adb path)/platform-tools/adb start-server
- If you had the Android Development Utility, such as 'ADT', 'Android-Studio' or 'GAT', you should be to try another 'adb' command-line it is much better to test your applications on a real device rather than just relying on the emulator.
$ ./adb root $ ./adb remount $ ./adb push filename(a file) /system/app(a path) $ ./adb pull /system/app(a path) filename(a file) $ ./adb shell
Exception
- If it still cannot recognize, you might restart your computer or reconnecting your USB cable.
By the way, you also try to edit the file (adb_usb.ini) as below.
$ cd ~ $ sudo gedit /.android/adb_usb.ini
File name: ~/.android/adb_usb.ini
# ANDROID 3RD PARTY USB VENDOR ID LIST -- DO NOT EDIT.
# USE 'android update adb' TO GENERATE.
# 1 USB VENDOR ID PER LINE.
# For example, if you had an HTC incredible S you would attend your vendor ID in this file.
0bb4
Therefore, you need to restart your computer.
- If you got a response message as likely as not this 'Undefined command: “adb”. Try “help”.” when you ran 'adb'. The mean that you need to install 'adb' package. 'adb' is part of the Android SDK. There are two ways to help you install.
2.1. Open terminal (Ctrl+Alt+T in Ubuntu). From the command-line, the installation can be completed by running the following command from the terminal.
$ sudo apt-get install android-tools-adb android-tools-fastboot
2.2. If you had Synaptic package management, you would search for 'android-tools-adb' package, select Mark for installation, then click on the Apply button.
2.3. Normally, using the Ubuntu Software Center (USC), search for the phrase 'android-tools-adb', highlight the package and select install.
- Take a look at this web site to download the Android SDK.
3.1. Open a web browser.
3.2. Go to http://developer.android.com/sdk/
- If you have been installing 'adb' package, but you got an error message. Such as 'No command 'adb' found'. You might add your 'adb' path in your PATH variable.
4.1. It seems the shell cannot find the command 'adb', so you need add 'adb' to your path variable. Normally, you are able to find out it in the Android SDK.
$ ./adb devices No command 'adb' found, did you mean: Command 'cdb' from package 'tinycdb' (main) Command 'gdb' from package 'gdb' (main) Command 'aub' from package 'aub' (universe) ... (more)
4.2. If you had 'adt-bundle-linux-x86_64-xxxxxxxx', you would be to find out it in this path ('your adt path'/sdk/platform-tools).
4.3. If you had 'android-studio', you would be to find out it in this path('your android-studio path'/sdk/platform-tools).
4.4. If you had 'adt-bundle-windows-x86_64-xxxxxxxx', you would be to find out it in this path ('your adt path'/sdk/platform-tools).
4.5. If you want to make any directories in Ubuntu, you should add them in your '.bashrc' it is much better for developing your applications.
$ cd ~ $ ls -la .bashrc ... (more) $ sudo gedit .bashrc
File name: .bashrc
# export PATH=('your adt path'/sdk/platform-tools):$PATH
# export PATH=${PATH}:('your adt path'/sdk/platform-tools)
For example, it is as likely as not as below.
export PATH=/home/tester/adt-bundle-linux-x86_64-20140702/sdk/platform-tools:$PATH
export PATH=${PATH}:/home/tester/adt-bundle-linux-x86_64-20140702/sdk/platform-tools
Once you are done, you will need to be sourced the file (.bashrc) if you want to change to be picked up, you are just to run a command-line.
$ . ./.brashrc
By other way, you could restart a new terminal and then it will be loaded new configuration file (.bashrc) by your edition.
- What is the rules format of the 'udev'?
If you want to know about the rules format of the 'udev', you would visit to this web site [4]. There are richly explained about 'udev' rules by [4].
Reference
[1] http://developer.android.com/index.html
[2] http://askubuntu.com
[3] http://dimitar.me/how-to-connect-your-android-phone-to-ubuntu-to-do-developmenttestinginstallations-or-tethering/
[4] http://reactivated.net/writing_udev_rules.html
Acknowledge
Thank you (Google, Ubuntu, Daniel Drake, Dimitar Darazhanski) very much for this fantastic method.