The Basics
When you develop Android applications (or, for that matter, the mobile applications for Windows Mobile or Apple’s iPhone), you would test the applications on an emulator that runs on your own development machine (a Windows Laptop or a Mac, etc. in other cases)
Of course, you would need a program to manage the emulator – pushing the files onto the emulator, running any shell commands, etc. That program for Android applications is ADB – Android Debug Bridge.
Ideally, you would want this to be transparent (in one scenario) to the developer and the basic tasks be taken care of behind the scenes by the IDE. Google’s Android Plugin for Eclipse uses the ADB to automatically launch the Android program in the emulator. This plugin piece is called DDMS (Dalvik Debug Monitor Service).
Where is ADB?
ADB is in the tools directory of the Android SDK. For example, for the version m5-rc15, the adb.exe file could be in the following directory.
D:\android\android-sdk_m5-rc15_windows\tools
If you included the tools directory in the system path, then you would be able to launch adb from anywhere in the console.
Available Commands
Just typing ‘adb’ at the command prompt gives a one page list of commands available with Android Debug Bridge.
Code Listing 1. Summary of Commands from ADB
C:\Users\Administrator>adb
Android Debug Bridge version 1.0.18
-d <device number> - directs command to a specific device
-p <product name or path> - simple product name like sooner, or
a relative/absolute path to a product
out directory like out/target/product/sooner.
If -p is not specified, the ANDROID_PRODUCT_OUT
environment variable is used, which must
be an absolute path.
devices - list all connected devices
device commands:
adb update DATAOPTS <file> - Flash the specified update file.
If file is not passed, update.zip is used.
adb push <local> <remote> - copy file/dir to device
adb pull <remote> <local> - copy file/dir from device
adb sync [ <localdir> ] - copy host->device only if changed
(see adb help all)
adb shell - run remote shell interactively
adb shell <command> - run remote shell command
adb logcat [ <filter-spec> ] - View device log
adb forward <local> <remote> - forward socket connections
forward specs are one of:
tcp:<port>
local:<unix domain socket name>
dev:<character device name>
jdwp:<process pid> (remote only)
adb jdwp - list PIDs of processes hosting a JDWP transport
adb install <app> - push this app to the data partition
adb bugreport - return all information from the device
that should be included in a bug report.
adb help - show this help message
adb version - show version num
DATAOPTS:
(no option) - dont touch the data partition
-w - wipe the data partition
-d - flash the data partition
bootloader commands:
adb flashall DATAOPTS - reflash the device from the build output tree
adb flash [<name>] [<file>] - write to flash
adb send <name> <file> - write to ram
adb debug - listen to bootloader debuglog
adb bl <command> - send raw bootloader command
scripting:
adb wait-for-bootloader - block until bootloader is online
adb wait-for-device - block until device is online
adb start-server - ensure that there is a server running
adb kill-server - kill the server if it is running
adb get-state - prints: offline | bootloader | device
adb get-product - prints: <product-id>
adb get-serialno - prints: <serial-number>
networking:
adb ppp <tty> [parameters] - Run PPP over USB.
Note: you should not automatically start a PDP connection.
<tty> refers to the tty for PPP stream. Eg. dev:/dev/omap_csmi_tty1
[parameters] - Eg. defaultroute debug dump local notty usepeerdns
adb sync notes: adb sync [ <localdir> ]
<localdir> can be interpreted in several ways:
- If it not specified, both /system and /data partitions will be updated.
- If it is "system" or "data", only the corresponding partition
is updated.
- If it is a path to a local directory, the name is examined to see if
it points to a directory named ".../system" or ".../data", or if
the directory contains subdirectories with those names. If so, it pushes
the appropriate directory/ies to the device.
- If the name of the local directory does not match ".../system" or
".../data", it is treated like an "system" directory.
- If <localdir> points to a nonexistent directory, adb sync will fail.
Currently Available Emulators / Devices
All the Android emulators that are currently running can be listed via the ‘devices’ command. The emulator listed below was started by Eclipse (via the Plugin) while I was debugging that program. That emulator can be seen from the adb on the command line.
Code Listing 2. Obtaining the current list of emulators / devices
C:\Users\Administrator>adb devices
List of devices attached
1 emulator-tcp-5555 device 0
You can look into the above emulator/device closely via the shell, by issuing the command ‘adb –d 1 shell’, where 1 is the device id as shown in the list of devices above.
In the code listing below, directory listing commands (ls) show what’s on the emulator. Type ‘exit’ or ‘Ctrl-D’ to come out of that shell.
Code Listing 3. Some sample Shell Commands
C:\Users\Administrator>adb -d 1 shell
# ls
ls
cache
d
init
etc
var
data
system
sys
tmp
proc
sbin
root
dev
# cd data
cd data
# ls
ls
timezone
anr
checkin.db
system
dalvik-cache
data
download
logs
drm
misc
app
lost+found
# cd app
cd app
# ls
ls
NotesList.apk
ApiDemos.apk
# pwd
pwd
/data/app
What Commands are available from the shell?
Obviously, this is a mobile device. So, the shell isn’t super-powerful. The directory listing from /system/bin provides a peek into the commands available. As you can see, you have ls, ps, chmod, wipe, rm, rmdir, kill, etc. are available.
Code Listing 4. Contents of system/bin
# pwd
pwd
/system/bin
# ls -l
ls -l
-rwxr-xr-x root root 196 2008-02-29 01:09 am
-rwxr-xr-x root root 2342 2008-02-29 01:09 dumpstate
-rwxr-xr-x root root 208 2008-02-29 01:09 input
-rwxr-xr-x root root 212 2008-02-29 01:09 monkey
-rwxr-xr-x root root 196 2008-02-29 01:09 pm
-rwxr-xr-x root root 1027 2008-02-29 01:10 ro.xml
-rwxr-xr-x root root 1782 2008-02-29 01:10 ro2.xml
-rwxr-xr-x root root 98 2008-02-29 01:10 roerror.xml
-rwxr-xr-x root root 411 2008-02-29 01:10 ssltest
-rwxr-xr-x root root 10340 2008-02-29 01:16 debuggerd
-rwxr-xr-x root root 77520 2008-02-29 01:16 linker
-rwxr-xr-x root root 3092 2008-02-29 01:16 mtptest
-rwsr-xr-x root root 27648 2008-02-29 01:16 ping
-rwxr-xr-x root root 93944 2008-02-29 01:16 sh
-rwxr-xr-x root root 7852 2008-02-29 01:16 showslab
-rwsr-sr-x root root 68716 2008-02-29 01:16 su
-rwxr-xr-x root root 4076 2008-02-29 01:16 crasher
-rwxr-xr-x root root 3776 2008-02-29 01:16 dvz
-rwxr-xr-x root root 7284 2008-02-29 01:16 install_boot_image
-rwxr-xr-x root root 9432 2008-02-29 01:16 logcat
-rwxr-xr-x root root 9868 2008-02-29 01:16 netcfg
-rwxr-xr-x root root 148832 2008-02-29 01:16 pppd
-rwxr-xr-x root root 21908 2008-02-29 01:16 rpc_test
-rwxr-xr-x root root 3340 2008-02-29 01:16 rpcon
-rwxr-xr-x root root 5632 2008-02-29 01:16 showmap
-rwxr-xr-x root root 18340 2008-02-29 01:16 usbd
-rwxr-xr-x root root 65828 2008-02-29 01:16 toolbox
-rwxr-xr-x root root 122368 2008-02-29 01:16 dbus-daemon
-rwxr-xr-x root root 4936 2008-02-29 01:16 dog
-rwxr-xr-x root root 51536 2008-02-29 01:16 pcm
lrwxr-xr-x root root 2008-02-29 01:16 powerd -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 printenv -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 r -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 reboot -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 ps -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 readtty -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 renice -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 resetradio -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 rm -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 rmdir -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 rmmod -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 rotatefb -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 route -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 sendevent -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 setconsole -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 setkey -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 setprop -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 sleep -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 smd -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 start -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 stop -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 sync -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 syren -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 umount -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 watchprops -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 wipe -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 cat -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 cmp -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 chmod -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 date -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 dd -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 df -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 dmesg -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 exists -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 getevent -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 getprop -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 hd -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 ifconfig -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 insmod -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 ioctl -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 kill -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 ln -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 log -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 lsmod -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 ls -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 mkdir -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 mkdosfs -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 netstat -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 mount -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 notify -> toolbox
-rwxr-xr-x root root 28032 2008-02-29 01:16 dexdump
-rwxr-xr-x root root 7100 2008-02-29 01:16 dumpsys
-rwxr-xr-x root root 7904 2008-02-29 01:16 mem_profiler
-rwxr-xr-x root root 6480 2008-02-29 01:16 service
-rwxr-xr-x root root 4320 2008-02-29 01:16 rild
-rwxr-xr-x root root 4928 2008-02-29 01:16 sdutil
-rwxr-xr-x root root 26488 2008-02-29 01:16 sqlite3
-rwxr-xr-x root root 4148 2008-02-29 01:16 dexopt
-rwxr-xr-x root root 4908 2008-02-29 01:16 dalvikvm
-rwsr-sr-x root root 3200 2008-02-29 01:16 surfaceflinger
-rwxr-xr-x root root 5420 2008-02-29 01:16 app_process
-rwxr-xr-x root root 39408 2008-02-29 01:16 runtime
-rwxr-xr-x root root 2920 2008-02-29 01:16 system_server
-rwxr-xr-x root root 9168 2008-02-29 01:17 pv
Related Articles
Using ADB – Android Debug Bridge
Peering into an Android Device via the shell
Using SQLite from Shell in Android