-
Notifications
You must be signed in to change notification settings - Fork 0
Android Debug Bridge (ADB)
The Android Debug Bridge (ADB) is a command line tool used for communicating between a testing client (i.e laptop) and a testing device (ie mobile phone/emulator)
It is formed of:
- Client that sends commands
- Daemon that runs the commands (adbd)
- A server that manages the communications between the client and daemon
Default Ports:
- TCP 5037
The ADB server will detect emulators running or connected running devices by scanning odd numbered ports from TCP 555-5585.
Install Path:
Android_SDK/platform-tools/
If you get connectivity issues try the following:
- Start ADB before the emulator
- Stop/restart the ADB server
- Kill all ADB processes
Full reference: https://developer.android.com/studio/command-line/adb.html#issuingcommands
| Command | Description |
|---|---|
| -a | listen on all network interfaces |
| -d | direct adb to USB |
| -e | direct adb to emulator |
| devices -l | list all devices |
| shell | get a shell on device |
| shell {command} | run a command on a device |
| push /path/to/file /place/to/save/file | push a file |
| pull /path/to/file /place/to/save/file | pull a file |
| forward tcp:{local-port} tcp:{device-port} | TCP forwarding |
| logcat | view device logs |
You can issue commands to the adb package manager tool to perform actions on app packages installed on the device.
adb shell pm {command}
| Command | Description |
|---|---|
| list packages | prints all packages |
| list permissions | prints all known permissions |
| path com.package.name | prints the path of the package |
| install com.package.name | installs a package |
| uninstall com.package.name | uninstalls a package |
If you have just installed an application and want to find where it is installed so you can pull the apk you could run the following:
adb shell pm list packages | cut -f 2 -d ":"
adb shell path <package name from above>
adb pull /path/to/app/from/above
You can issue commands to the activity manager to perform system actions like starting or stopping a process, initiating an activity, broadcasting an intent etc.
adb shell am command
| Command | Description |
|---|---|
| start [options] intent | Start an activity specified by intent |
| start -a android.intent.action.View | example of above |
| startservice [options] intent | start the service specified by intent |
| force-stop package | stop the package |
| kill-all | kill all processes |
| broadcast [options] intent | Issue a broadcast intent |
| dumpheap process file | dump the heap of a process to a file |
| Command | Description |
|---|---|
| -a action | specify the intent action |
| -d data_uri | specify the intent data URI content://blah |
| -n component | specify the component name with the package name prefix which creates an explicit intent com.foo.bar/.FooBarActivity |
| -f flags | flags passed to the intent |
| -e extra_key extra_string_value | string data as a key-value pair |
| --ez extra_key extra_boolean_value | boolean data as a key-value pair |
| --ei extra_key extra_int_value | integer data as a key-value pair |