Friday 14 November 2014

Friday 14 November 2014

ADB (Android Debug Bridge): Commands

Listing of adb Commands



The table below lists all of the supported adb commands and explains their meaning and usage.
CategoryCommandDescription
Options-dDirect an adb command to the only attached USB device.
-eDirect an adb command to the only running emulator instance.
-s <serialNumber>Direct an adb command a specific emulator/device instance, referred to by its adb-assigned serial number (such as "emulator-5556").
GeneraldevicesPrints a list of all attached emulator/device instances.
helpPrints a list of supported adb commands.
versionPrints the adb version number.
Debuglogcat [<option>] [<filter-specs>]Prints log data to the screen.
bugreportPrints dumpsysdumpstate, andlogcat data to the screen, for the purposes of bug reporting.
jdwpPrints a list of available JDWP processes on a given device.
Data




install <path-
to-apk>
Pushes an Android You can use the forward jdwp:<pid> port-forwarding specification to connect to a specific JDWP process. For example:adb forward tcp:8000 jdwp:472
jdb -attach localhost:8000
application(specified as a full path to an .apk file) to the data file of an emulator/device.
pull <remote> <local>Copies a specified file from an emulator/device instance to your development computer.
push <local> <remote>Copies a specified file from your development computer to an emulator/device instance.
Ports and Networkingforward <local> <remote>Forwards socket connections from a specified local port to a specified remote port on the emulator/device instance.

ppp <tty> [parm]...Run PPP over USB.
  • <tty> — the tty for PPP stream. For exampledev:/dev/omap_csmi_ttyl.
  • [parm]... — zero or more PPP/PPPD options, such as defaultroute,localnotty, etc.
Note that you should not automatically start a PDP connection.
Scriptingget-serialnoPrints the adb instance serial number string.
get-statePrints the adb state of an emulator/device instance.
wait-for-deviceBlocks execution until the device is online — that is, until the instance state is device.

Serverstart-serverChecks whether the adb server process is running and starts it, if not.
kill-serverTerminates the adb serverprocess.
ShellshellStarts a remote shell in the target emulator/device instance.
shell [<shellCommand>]Issues a shell command in the target emulator/device instance and then exits the remote shell.



The ADB tool is launched from the command line.
At your command prompt, simply type:
1
adb
This runs ADB and shows a list of a bunch of commands.
If you do not see the list of commands, go back and check your installation and environment path settings, as described in previous tutorials. It could be that you have the ADB program installed, but if you don't have your shell's PATH environment variable configured correctly, you would need to type the full file path to ADB at the terminal to launch the program. Done? Good.
So back to that list of commands. The ADB tool serves two purposes. The first is to allow many of the other Android tools to interact with devices and emulators. The second is to allow you, the developer, to talk to devices and emulators by issuing different commands manually.
ADB commands come in two forms. One form of command you run directly from ADB. Another form of command, which isn't directly ADB but is commonly done through ADB, is done through the "adb shell" command.
Now, before going on, have an emulator instance running or an Android device connected to your development machine. Now, if you use the ADB devices command, it should list any attached devices or emulator instances:
1
adb devices
You should see something like this:
If not, make sure your emulator is running or restart the ADB server.
To restart the ADB server, here's another command for you:
1
2
adb stop-server
adb start-server
Once you're ready to, continue on. We'll be covering many commands, in no particular order.
Here are a variety of commands run directly via ADB. This will be followed by several commands that first require opening a shell.
You can copy files to and from a connected device using the ADB push and ADB pull commands.
1
2
adb push <local source file path> <device destination file path>
adb pull <device source file path> <local destination file path>
These commands are very useful for things like refreshing preference XML files for your app during testing, and other such things.
You can use ADB to install or remove apps (apks) from your devices. Use the install command to install an Android package file/
1
adb install <file path to apk>
Likewise, you can remove an existing app by its package name.
1
adb uninstall <package name>
You may find yourself needing to uninstall apps if you're moving between development machines that don't share the same app signing key. It's also a fast way to clean up, or load up, a device without having to use Eclipse and the ADT plug-in.
You can backup and restore the contents of a device. This has limitations on devices that aren't rooted.
1
2
adb backup
adb restore <archive name>
See 'adb help' for all the options of backup and restore. This could be useful for storing off app data during testing and then restoring this data easily for repeat testing.
You can reboot a device either normally, into the bootloader, or into recovery mode.
1
2
3
adb reboot
adb reboot recovery
adb reboot bootloader
In our experience, these aren't appropriate for the emulator. However, there are times with Android devices get confused and need a hard reboot.
The ADB tool has a shell interface. To issue shell commands, you must first launch this interface by typing adb shell:
1
adb shell
Once run, you'll be in a bash environment. You can run bash commands, like df to show free disk space, uptime to see how long the device has been running or exit to exit the shell interface:
If you're not familiar with Linux, you may have a harder time getting around in the shell. There are numerous guides online that will provide you with help for bash commands such as ls, cp, cd, and so on.
Here are several special commands you can run when in the shell. Not all ADB shell commands work on physical devices or emulators.
You can use the logcat command to view logging output much as you do in Eclipse:
1
2
3
adb shell
logcat --help
logcat -t 5
undefined
There are many options available with the logcat tool. By default, the output comes in real time, much like it does when viewed with Eclipse. One feature that's nice is you can send the output to a file using the -f option.
The bmgr tool is the backup manager. You can use this tool to trigger app-level data backup and restore operations. Your app must support backups for this to be useful.
You can use the monkey tool to test your apps. This simulates a variety of different user input events, much like a monkey or toddler banging on a keyboard. Use this for stress testing.
The monkey tool can be scripted, as well, and supports repeatable streams of events through the -s switch, so tests can be reviewed and repeated.
You can run sqlite commands and interact with application databases using the adb shell as well. You'll need read/write access to the databases you're interested in inspecting or altering (in other words, your own apps, not others).
undefined

1 comment:

  1. Thank you for your post. This is excellent information. It is amazing and wonderful to visit your blog.
    Best ios training institute in bangalore
    iOS app training in bangalore

    ReplyDelete