How To: A beginners guide to Android’s ADB for Mac OSX.

As much as I piss and moan about people needing to install the Android SDK if they intend to mod their phone, I feel obligated to do a tutorial.

While the title specifically states “For Mac”, that really only applies to the installation. Once you have the SDK installed, the commands are more or less the same in ADB.

Installation (Mac Specific)

1. Download the SDK. It will come in the form of a zip. Extract it somewhere easy, like the root of your username. You’ll get a folder called “Android-sdk-mac_86″ or something similar.

2. In finder, navigate to the sdk, then find the tools folder. Open it, and double click “Android”. It will launch a terminal window, then a few seconds later, a GUI. On the left, click on “Available Packages”, then in the right pane, check the box to select all, and hit “install selected”.

It will download quite a bit of data, so depending on your connection speed, it may take a while. While you’re waiting on that, use my tutorial to set up a bash profile.

3. On your Android phone, go to Settings > Applications > Development, and make sure “USB Debugging” is checked. Connect your phone to your computer with the USB cable.

4. Assuming the SDK is fully installed and downloaded, close the terminal window it opened and the gui. Open a new terminal window. If you’re not sure how, press Command + Space and type “Terminal” then enter. You’ll get a black box with text. Type “adb devices” and press enter. If everything worked, it will return a device ID to indicate your phone is connected and detected by ADB.

Navigating Basics

In order to effectively use ADB, you need a basic grasp of navigating your computer from terminal. Opening a terminal session will start you at the root of your user name, in finder, this will be your user name in the left hand pane, right under “desktop”. Entering

~/

or

cd

will get you back here.

If you intend to flash an img, push a file, etc, the easiest way to do so is to navigate to the directory in which the file is located. For example, if you want to push (I’ll explain what “push” means in a few, just stay with me) a file that is located on your desktop, and is named yourfile.zip to the SD card on your phone, you can either use

adb push ~/username/desktop/yourfile.zip /sdcard

from anywhere in terminal, since you’re using the full path to the file, or you can first navigate to the file’s location:

cd desktop

and then

adb push yourfile.zip /sdcard

which doesn’t require the full path, but rather works from the current directory.

Either way, you need a basic idea either how to determine the full path of a file, or how to navigate to the file’s location. Let’s cover the basics.

cd – Change Directory. This is what you’ll use more than anything. The format is

cd (location)

For example, let’s say you have a folder on your desktop named “android”, and inside that folder you have a folder named “apps”. To get there from ~/, you would enter

cd desktop/android/apps

Now let’s verify our location in terminal.

pwd

Now use ls to list the files in that folder

ls

That pretty much covers the basics. A few shortcuts:

  • cd will take you back to the root of your name from anywhere
  • cd .. will take you up one directory
  • ls -a will show all files

ADB Commands

adb push

adb push will “push” a file from your computer to your phone. The format is

adb push (location on computer) (destination on phone)

For example, let’s say you navigate to your desktop, and you want to move the file “song.mp3″ to the folder “music” on your phone’s SD card.

adb push song.mp3 /sdcard/music/

adb pull

adb pull is exactly the opposite. To pull song.mp3 from the music folder on your sdcard to your desktop:

adb pull /sdcard/song.mp3 ~/desktop/

adb install

adb install will you install an app via adb, using an apk file on your computer. If you have app.apk downloaded to your desktop, and have navigated to desktop in terminal

adb install app.apk

You need to have “Unknown sources” checked on your phone, found at settings > applications for this to work.

adb logcat

adb logcat is insanely valuable in trying to diagnose issues. Simply enter

adb logcat

and you’ll start to get a real time log of everything going on with your phone. It might not mean much to you, but it can be a valuable tool when asking for help.

That’s all I feel like writing for now, I’ll cover ADB shell, fastboot, and perhaps more extensive stuff later. Hope this helps.

How To: Create a .bash_profile on your Mac running OSX Snow Leopard to run Android ADB from any folder and without ./

The Android SDK is very easy to get up and running on OSX, it doesn’t require any drivers or anything, just run the android app and it does it’s thing.

Unfortunately, OSX doesn’t have a .bash_profile by default. Without creating a .bash_profile and adding your sdk/tools folder to path, you’ll need to navigate to the tools folder of your sdk and run scripts locally when using stuff like ADB and fastboot.

I know that just gave you a headache, so I’ll clarify with examples.

Let’s say you download the sdk, and unzip it to yourusername/android-sdk-mac_86

In order to run adb, you’ll need to open terminal, and type

cd android-sdk-mac_86/tools

then you’ll need to start every command with the dot slash ( ./ ), which tells the terminal to run commands from the folder you are currently in.

For example,

adb shell

attempts to run the script adb, with the command shell, to open a shell, and it looks for the scripts where ever it thinks scripts will be. On a Mac, it only looks in /bin by default. This is where the scripts for the commands you use to navigate in terminal are stored. It contains stuff like ls, mkdir, cd, etc.

If you want it to run a script from your current location in terminal, you have to add the dot slash. For example, still in your sdk/tools folder, the command

./adb shell

Will attempt to run the script “adb” with the command “shell” from your current location, in this case, sdk/tools.

We’re going to add sdk/tools to the places OSX looks for scripts, so you don’t need to be in that folder in order to use adb or any other SDK script. For instance, you can navigate to the desktop and use ADB to install an APK on your desktop without moving it to the tools folder. Clear as mud? Great.

Press Command (apple) + space and a spotlight search window will pop up in the upper right corner. Start typing “Terminal” until you see it highlighted, and press enter. A terminal window will open.

Type:

cd

Press enter. You should be in your root directory.

Now type:

touch .bash_profile

then press enter. You just created a file called “.bash_profile”. Now open it with text editor using this command:

open -e .bash_profile

Pressing enter will make text edit pop up, it’s likely blank, since you just created it. In the text file, paste this:

export PATH=${PATH}:/Users/yourname/whereveryoursdk/islocated/tools

Obviously replace yourname and the path to your sdk/tools folder with the correct info for your install.

Save the file and close text edit.

If you did it right, you’re done. With your android phone plugged in, type

adb devices

and if you get a device returned, you’re good to go.

12/07/10 Update:

It appears that updating your SDK to include all the new gingerbread stuff moves ADB from sdk/tools to /sdk/platform-tools. Basically, all you need to do is add one more line to .bash_profile. Under the line you added earlier, something like:

export PATH=${PATH}:/Users/yourname/whereveryoursdk/islocated/tools

Add this:

export PATH=${PATH}:/Users/yourname/whereveryoursdk/islocated/platform_tools


How To: Fastboot or ADB on Ubuntu returning no devices or “Waiting for Device”? Here’s how to fix it.

I was having some issues getting my devices recognized in fastboot/adb on Ubuntu.

“fastboot devices” just returned back to the terminal prompt, without showing any connected devices, so I tried using the -i option to specify a usb vendor ID, like “fastboot-linux -i 0x413c reboot”. This just hung on “waiting for device”. I kinda ignored it, since I actually use my mac for most fastboot/adb, but tonight I was bored and fucking off on the CyanogenMod forums shoutbox, and someone was having the same problem. I did a bit of googling and found a solution that worked for me (and M.P.)

As usual, I’m not responsible for fucking your phone up or accidentally dividing by zero or going back to the future or hacking the gibson or anything else that happens. I’m not an expert. I wouldn’t listen to me, I’m kinda an asshole, I have no idea what I’m talking about, I’m usually just guessing. Proceed at your own peril, etc, etc, etc.

Here’s the step by step fix, assuming you’re running ubuntu 10.04:

1. Open a terminal window.

2. Log in as root.

sudo -i

3. Create a UDEV rule file.

cat > /etc/udev/rules.d/51-android.rules

This should give you a blinking cursor at the very beginning of a blank line, it’s waiting for you to tell it what the file needs to contain.

4. Enter this AFTER YOU REPLACE “XXXX” WITH YOUR VENDORID:

SUBSYSTEM=="usb", SYSFS{idVendor}=="XXXX", MODE="0666"

(You can find your vendor ID on this page.
For example, for my Dell Streak, I would use:

SUBSYSTEM=="usb", SYSFS{idVendor}=="413c", MODE="0666")

5. Press CTRL + D to save, it should return you to the terminal prompt

6. chmod the new file

chmod a+r /etc/udev/rules.d/51-android.rules

7. Try fastboot. It should work now.

fastboot devices

Hopefully you get “Attached devices” with your devices serial number, if so, you’re good to go, fastboot should no longer hang at “waiting for device”. To be sure, try

fastboot reboot

If your device reboots, you win life.

OS X 10.6.3 is finally out!

Supposed to fix a few minor stability issues, the long rumored 10..6.3 just popped up in my software update.

I’ll report back later today if I notice any differences.