Mr. Pritesh N. Patel ISTAR Page 1 How to Use Android ADB Command Line Tool Android Debug Bridge (adb) is a tool that lets you manage the state of an emulator instance or Android phone. ADB is bundled with Android SDK package that can be downloaded from Android SDK download page. This tool is useful for communicating with Android phone such as install application, copy files from/to device and perform some linux shell commands. How to Install Download and install Java SDK (Ex: jdk-6u20-windows-i586.exe) Download Android SDK package (Ex: android-sdk_r06-windows.zip) Extract SDK package into anywhere on your drive (Ex: D:\android-sdk-windows) Phone Setup In order to use ADB, you have to enable USB Debugging option in phone settings (Settings->Applications->Development) How to Use Connect the phone to your pc/notebook usb port Run Windows command line tool (cmd) and go to D:\android-sdk-windows\tool Update!! New Android SDK puts adb executable file on \platform-tools directory instead of tool. So the path should be D:\android-sdk-windows\platform-tools Usefull Commands 1. Check connected phone Syntax: adb devices 2. Login to Android shell
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Mr. Pritesh N. Patel ISTAR Page 1
How to Use Android ADB Command Line Tool
Android Debug Bridge (adb) is a tool that lets you manage the state of an emulator instance or Android phone. ADB is bundled with Android SDK package that can be downloaded from Android SDK download page. This tool is useful for communicating
with Android phone such as install application, copy files from/to device and perform some linux shell commands.
How to Install
Download and install Java SDK (Ex: jdk-6u20-windows-i586.exe)
If you get ‘#’ after typing adb shell, you are already get root access on the phone, no need to type su. Otherwise if you get ‘$’ , type ’su’ to get root access (only for rooted device).
3. Some usefull shell commands
ls
List directory
Syntax: ls [path]
Example:
#ls /system/lib
cp
Copy file or directory
Syntax: cp [options] source dest
Note: To copy or delete files in Android root directories you have to change the
directory access mode to ‘read and write (rw)’ using command: remount rw
Example:
#remount rw
#cp /sdcard/libsec-ril.so /system/lib
#remount ro
mv
Move file or directory
Syntax: mv [options] source dest
Example:
#mv /system/lib/libsec-ril.so /sdcard/backup
chmod
Change file/directory permission
Syntax: chmod [-R] mode[,mode] …. file
Example:
#chmod 0644 /system/lib/libsec-ril.so
rm
Remove file or directory
Syntax: rm [options] file
Example:
#rm /system/lib/libsec-ril.so
4. Install application
You can use adb to install aplication from your local drive into phone. Syntax: adb install appname.apk
When buying an Android phone, sometimes it comes with preinstalled applications
either from manufacturer or network operator. These preinstalled applications can not be easily removed from application manager unless you have root access. If you already have root access, follow the following steps to remove the preinstalled applications:
Login into Android shell, you can use adb tool or terminal application such
as Android Terminal Emulator .
Type su to login as root
Type mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system to enable read-
write mode
Type cd /system/app, to enter the applications directory
Tyle ls to view the list of existing applications
Type rm AppilicationName.apk to delete an application. For example, to delete
Facebook app, just type rm Facebook.apk
Coding Tips: How to Use Custom Transition Animation in Android
Android has a set of Animation API that makes you easily create custom animations in your Android application. You can create animations programmatically via Java code or
defined them in xml files inside /res/anim folder. Using your custom animation, you can override the default transition animation between activities to make your app looks more
elegant. Overriding the default transition animation is easy, just create two custom animations and call the overridePendingTransition method of Activity class to use them.
How to use custom transition animation:
Create two animation files (xml), one for incoming activity (/anim/incoming.xml)
and one for outgoing activity (/anim/outgoing.xml).
If you are using an IDE, you’ll probably never realize the existence of the commands that
we are going to talk about, because IDEs provide an abstraction layer between the developer and the process implementation. However, if you happen to be an Android
enthusiast who loves to explore, read on to discover some command-line utilities that are useful both during development and debugging.
The command-line utilities that we shall be talking about are located in the Tools directory of your Android SDK installation. So without further ado, let’s delve
in: Adb Adb means ‘Android Debug Bridge’. Adb has a client-server mechanism, the client being
the Android emulator (or the device connected to your system) and the server being the system itself. Obviously, it can handle multiple client devices. To see the connected client devices, run the following command:
adb devices
You can also suffix parameters to the adb command, like:
adb -s <serial-number-of-client>
Other suffix options include -shell (gives you the client console), -logcat, install <.apk filename> (installs an Android app package), etc. Android This command lets you create Android Virtual Devices (AVD), Android projects and even
update the version of your Android platform.
When you create a new AVD/emulator, android creates a separate folder for the AVD with all the files required by it. To create an AVD, use this command:
android create avd -n <sample> -t <sample number>
-n signifies the name of the AVD while -t stands for the target ID of the Android version. To get the target ID, employ:
android list targets
To list the AVDs available on the system, use:
android list avd
To delete an AVD:
android delete avd -n <name>
DDMS
Mr. Pritesh N. Patel ISTAR Page 7
DDMS stands for Dalvik Debug Monitoring Service. It is a simple debugger tool. You can
launch it by using
ddms
command. When launched, it automatically links itself to the running emulators/AVDs.
In the right pane under the Sysinfo tab, it shows you the memory usage of each application, the CPU load, etc. You can view the running processes in the left pane.
Under the Emulator Control tab, if you enter a number in the ‘Incoming Number’ field, it will simulate an incoming call on the device.
In order to view the heap status, select a process from the left pane, click the ‘Show Heap Updates’ button at the top of the left pane and then click the ‘Cause GC’ button
under the VM Heap tab. You shall be able to see the heap update status and other related info.
Emulator
This command can be used to launch and control an emulator instance. Run:
emulator -avd <name>
This utility supports additional parameters, such as to view the console log:
emulator -avd <name> -logcat
To disable the Android animated logo at startup:
emulator -avd <name> -no-boot-anim
To open a root prompt or shell:
emulator -avd <name> -shell
Mr. Pritesh N. Patel ISTAR Page 8
Every emulator instance, by default, runs behind a virtual router/firewall. The default IP addresses of emulators are between 10.0.2.0 and 10.0.2.99
To connect to the emulator control console, use:
telnet localhost <console-port-num, eg. 3432>
Mksdcard
This command creates an SD card disk image (FAT32 file system):
mksdcard -l <label> <size> <filename>
Eg.:
mksdcard -l SB 1024M mobilemag.img
The above example will create an SD card image named mobilemag.img sized 1 GB with
label SB. To ‘insert’ this card image into an emulator, use:
emualator @<name> -sdcard mobilemag.img
Sqlite3
It is used to enter the SQLite database. It can create/modify/edit databases for the emulator/AVD. The command must be run from the shell prompt:
emulator @<name> -shell
# sqlite3
sqlite3>
More often than not, the application database would be stored in /data/data//databases SQLite3 follows the standard SQL syntax. So to create a table awesomeppl with their
In order to use Traceview to profile apps, you must pass a Debug.startTracingMethod(String tracename)function call at the beginning and
a Debug.stopTracingMethod() method call at the end of the function. The tracing info will be stored onto the SD card, so your emulator must have an SD card image attached to
it. Thus, the application will need permissions to write data to the card image (via AndroidManifest):
To drop into a remote shell on a emulator/device instance, use the shell command like
this:
adb [-d|-e|-s {<serialNumber>}] shell
When you are ready to exit the remote shell, use CTRL+D or exit to end the shell
session.
The sections below provide more information about shell commands that you can use.
Examining sqlite3 Databases from a Remote Shell
From an adb remote shell, you can use the sqlite3 command-line program to manage
SQLite databases created by Android applications. The sqlite3 tool includes many useful
commands, such as .dump to print out the contents of a table and .schema to print the
SQL CREATE statement for an existing table. The tool also gives you the ability to
execute SQLite commands on the fly.
To use sqlite3, enter a remote shell on the emulator instance, as described above, then
invoke the tool using thesqlite3 command. Optionally, when invoking sqlite3 you can
specify the full path to the database you want to explore. Emulator/device instances store SQLite3 databases in the folder /data/data/<package_name>/databases/.