Setting Up ADB on Linux

ADB is a tool used to connect and send commands to your Android phone from a desktop or laptop computer. In other words, it’s like the command center. ADB is a very important tool, it is used for various purposes, from rooting your phone to messing with system codes. A Developer/Themer is crippled without ADB and if you’re just an average user, you will still need it… Don’t you want all that sweet ROMs and Mods? On this guide, I will be using Xubuntu 12.04, a flavour of Ubuntu (No Big Difference Really.)

To set up ADB on Linux, you’ll need to download some files and said files are a bit heavy. Just don’t try to do this on a 512 kbits connection.


Part I: Installing the JDK

First, we’ll need to install the JDK (Java Development Kit.) We’ll need to use Oracle Java instead of OpenJDK in Ubuntu. Thanks to WebUpd8 for providing an installer.

Oracle JDK7 itself is not hosted in the PPA because that’s not allowed by the new Java license (which is also the reason why it has been removed from the official Ubuntu repositories); the package in the PPA automatically downloads (and installs) Oracle Java JDK 7 from its official website and installs it on your computer, just like the flashplugin-installer package does.

Chances are you already have OpenJDK installed, if you do, then run this command in the Terminal.

sudo apt-get purge openjdk*

The command given above will purge OpenJDK. Now we’re ready to install the JDK. Type these commands into the Terminal:

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer

After the installation finishes, if you want to check if it was successful, then run this command:

java -version

It should give an output similar to this:

java version "1.7.0_10"
Java(TM) SE Runtime Environment (build 1.7.0_10-b18)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

Linux Mint Users!

If you use mint… you don’t need Oracle Java, you can go with OpenJDK

Just open the terminal and issue:

sudo apt-get install openjdk-7-jdk

Part II:Installing Android SDK

The Android Software Development Kit (SDK) includes a comprehensive set of development tools. These include a debugger , librairies, a handset emulator based on QEMU, documentation, sample code, and tutorials. It contains ADB and you’ll need it.

Head over to the Android Developer Website and download the SDK.

Download SDK Tools, not the ADT Bundle.

Download SDK Tools, not the ADT Bundle.

After you get the .tgz file. Go to your Home and, to keep things organized, I suggest making a folder called “Android” or “Andy” in there and extracting it there. After you’re done extracting, you’ll get a folder called “android-sdk-linux.” We’ll be doing some terminal commands, so, to make the name short, we’ll rename it to “sdk.

Open “sdk” folder and navigate to “tools” in which you’ll find a file simply called “android” . That is actually the Android SDK Manager. After opening it untick everything other than “Tools” :

Android SDK Manager _010

Click on “Install 2 Packages”, I already have it installed.

Part III: The Setting-Up Part

On your Android Phone, go to Settings > Applications > Development and in there enable USB Debugging. Plug it into your PC and throw this command in the terminal:

lsusb

You will get an output similar to this:

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 004 Device 003: ID 19d2:fffe ZTE WCDMA Technologies MSM
Bus 001 Device 004: ID 1c9e:9e08 OMEGA TECHNOLOGY

My phone is the last one. To figure out which one is your phone, just disconnect your phone, enter the command and check which one is missing.

See that part in red, that is my the Manufacturer and Model ID of my Andy. Write it down somewhere. Now we need to create a udev rules file, enter this command:

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

It creates a text file in which you will have to input some details, Put it in this format:


#x-x-x-x-x-x
SUBSYSTEM=="usb", ATTR{idVendor}=="xxxx", ATTR{idProduct}=="xxxx", MODE="0666", GROUP="adbandy"


The Format Explained

#x-x-x-x-x-x = Replace the “x-x-x-x-x-x” with the name of your manufacturer. For example, for Samsung it’s “#Samsung”

ATTR{idVendor}==”xxxx” = Replace the “xxxx”  with your Manufacturer ID, which in my case is 1c9e

ATTR{idProduct}==”xxxx” = Replace the “xxxx” with your Product ID, which in my case is 9e08.

GROUP=”adbandy = I set up a group called adbandy and included myself in it, you don’t have to do it. You can replace adbandy with “plugdev”


After you’re done doing the above, save it and close.

Next, Open your “Home” Directory and configure it to show hidden files and folders by pressing Ctrl + H. A bunch of Files and Folders will show up. Find the .android folder and open it. In there, you will find a file called adb_usb.ini, open it, it’ll look like this:

-adb_usb.ini_008

Replace the red Xs in “0xxxxx” with your Vendor ID and put it right under “# 1 USB VENDOR ID PER LINE”.

Note: If you don’t have adb_usb.ini, cd to /sdk/tools/ and issue the following commands:

# ./android update adb
# cd ../platform-tools/
# ./adb kill-server
# sudo ./adb start-server

After you are done, it should look like this:

adb_usb.ini_007

Save and close.

Open a Terminal and shoot this command: —–Note: The “Android” in the command is the folder in which we extracted the SDK in.

cd ~/Android/sdk/platform-tools/

Then enter these commands, one by one:

sudo service udev restart
./adb kill-server
./adb start-server
./adb devices

After you issue the last command, if you get an output like this;

Terminal - jason@jason-desktop: ~-sdk-platform-tools_012

Congratulations, you have successfully set up ADB on your Linux Box!!!


But if you get a different output then you can move on to the “Extras” Section where problems and there Solutions are given.

Extras

Problem 1: After following all the instructions above, I get the output above with nothing under “List of devices attached”, what do I do?

Solution: I had this problem. After a lot of running around, I found the solution. Run the commands given below. Note: This might not work for some but you can try.


sudo cp /lib/udev/rules.d/40-usb_modeswitch.rules /etc/udev/rules.d/usb_modeswitch.rules
sudo gedit /etc/udev/rules.d/usb_modeswitch.rules

The last command will launch a text file with a lot of stuff in it. At the end of the text file, before the modeswitch_rules_end, add one more entry. The format of the entry is given below, you need to use the details of your phone — The format was explained in the part where we set up udev rules.

#x-x-x-x-x-x
ATTR{idVendor}=="xxxx", ATTR{idProduct}=="xxxx", RUN+="usb_modeswitch '%b/%k'"

Then run:

sudo usb_modeswitch -v 0x1c9e -p 0x9e08 -S -R -W

Replace my Manufacturer ID and Product ID with yours…

Problem 2: After doing all the above, I get “???????????        no permissions”

Solution: cd to your platform-tools directory and run these commands:

# sudo service udev restart
# ./adb kill-server
# sudo ./adb start-server

__________________________________________________________________________________________________________________________________

Thank you for taking your time to read this article. This is the first post on Android On Linux.

Comment. Gimme a Thumbs Up. Gimme some Hate. Gimme Whateva. 🙂

If you have any problems, don’t hesitate to let me know.

Advertisements

11 thoughts on “Setting Up ADB on Linux

  1. Pingback: Android On Linux

  2. Pingback: Basic requirements for build SEAndroid - SEAndro

  3. Just what I needed, an excellent write up – thanks for taking the time to write this.

    Two thumbs up

    • Thank you! BTW, Just asking — Which Device do you own? Can you mention the Manufacturer, Android Version and Device Model too?

      • I mainly use old phones that people are throwing away or cheap ones.
        At the moment I have an Alcatel OT 990 upgraded to gingerbread and running a custom rom – v5h60 mod from EwRa blogspot.
        It’s very fast and lightweight and has good battery life unlike a lot of the other custom roms for that model. I really wanted the cyanogen mod but the “stable” version doesn’t like my sim card.

        I’ve just picked up a new Huawei Y201 pro for under $40 which is running ICS, I’ve rooted it and now I’m looking around for a lightweight rom that is stable.

    • OK… Well, Why don’t you trying making your own Custom ROM? It’s pretty easy… I can help you if you want.

      • I’d love to start making my own ROMs. I don’t want to hijack this topic with questions about it though. All I’ve done so far is pulled a few apk’s of the standard ROM’s to trim them down a bit

        Maybe you could do a page on that ?

        Hoards of people are buying the Y201’s because they are so cheap, many are happy to mod them because of the low finacial risk if they brick them, but there is a definite lack of options at the moment.

        Most of the development is going into higher spec phones.

        There might even be a few bucks to be made, because of the sheer volume of units out there (Y201)

  4. Maybe all I could add would be to update your libraries if you get the error below when trying to run adb

    bash: ./adb: No such file or directory

    I was getting the error & I did
    sudo apt-get install ia32-libs-multiarch

    Now everything works fine

    • Sorry about that and I know I’m a bit late! Windows messed up my bootloader… Anyway, I forgot to mention about the 64-bit-lib files thingy, I’ll ad that to the article! Thanks for commenting!

  5. man…. you really are saving me from headache. i have been searching this solution for months. two thumbs up for you bro. and by any chance your vendor and product id are exactly the same with mine, so its far easier for me to follow. thank you so much. i hope your article is saving many other people out there who have the same headache as mine 😀

  6. Pingback: Rooting my Droid | Cabra 219's Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s