ADB Commands

Information obtained from: http://adbshell.com/****

Connection

adb devices

This will list the connected devices; if "unathorised" appears, this means that you have to unblock your mobile and accept the connection.

This indicates to the device that it has to start and adb server in port 5555:

adb tcpip 5555

Connect to that IP and that Port:

adb connect <IP>:<PORT>

If you get an error like the following in a Virtual Android software (like Genymotion):

adb server version (41) doesn't match this client (36); killing...

It's because you are trying to connect to an ADB server with a different version. Just try to find the adb binary the software is using (go to C:\Program Files\Genymobile\Genymotion and search for adb.exe)

Packet Manager

Install/Uninstall

adb install [option] <path>

adb install test.apk

adb uninstall [options] <PACKAGE>

Packages

Prints all packages, optionally only those whose package name contains the text in <FILTER>.

adb shell pm list packages [options] <FILTER-STR>

adb shell pm path <PACKAGE>

Print the path to the APK of the given .

adb shell pm clear <PACKAGE>

Delete all data associated with a package.

File Manager

adb pull <remote> [local]

Download a specified file from an emulator/device to your computer.

adb push <local> <remote>

Upload a specified file from your computer to an emulator/device.

Screencapture/Screenrecord

adb shell screencap <filename>

Taking a screenshot of a device display.

adb shell screenrecord [options] <filename>

Recording the display of devices running Android 4.4 (API level 19) and higher.

(press Ctrl-C to stop recording)

You can download the files (images and videos) using adb pull

Shell

adb shell

Get a shell inside the device

adb shell <CMD>

Execute a command inside the device

Processes

If you want to get the PID of the process of your application you can execute:

And search for your application

Or you can do

And it will print the PID of the application

System

Restarts the adbd daemon with root permissions. Then, you have to conenct again to the ADB server and you will be root (if available)

flashing/restoring Android update.zip packages.

Logs

Logcat

To filter the messages of only one application, get the PID of the application and use grep (linux/macos) or findstr (windows) to filter the output of logcat:

adb logcat [option] [filter-specs]

Notes: press Ctrl-C to stop monitor

adb logcat -b <Buffer>

dumpsys

dumps system data

adb shell dumpsys [options]

adb shell dumpsys meminfo

Notes: A mobile device with Developer Options enabled running Android 5.0 or higher.

Notes: Battery Historian converts that data into an HTML visualization. STEP 1 adb shell dumpsys batterystats > batterystats.txt STEP 2 python historian.py batterystats.txt > batterystats.html

adb shell dumpsys activity

Backup

Backup an android device from adb.

最后更新于

这有帮助吗?