Device-related commands
To get devices on all connections:
ADB devices
Specify a unique USB connection device:
Adb–d <serialNumber> <command>
Specify unique emulator:
Adb–e <serialNumber> <command>
When you have multiple phones and emulator:
Adb–s <serialNumber> <command>
ADB services related
Close ADB server
ADB kill-server
Start ADB server
ADB start-server
Get read and Write access to/system: adb remount
Commands related to the data operation:
Install APK
ADB install–r <path_to_apk>
Reinstall the App,keep its data
Abd Install–s <path_to_apk>
Install on SD card
ADB install <path_to_apk>
eg. ADB install c:\Launcher2.apk
Uninstall APK
ADB uninstall–k <packagename>
Keep the data and cache directories
If you want to uninstall the app that comes with Android, first get root permission, then delete the APK and uninstall the package as shown on the right to uninstall the default Launcher2 command:
ADB uninstall <packagename>
eg. ADB uninstall Com.android.launcher2
eg.
ADB remount
ADB Shell RM system/app/launcher2.apk
ADB uninstall Com.android.launcher
Copy files from Device/emulator to local
ADB pull <remote> <local>
eg. ADB pull mnt/sdcard/mtklog/d:\log\
Copy Local files to Device/emulator
ADB push <local> <remote>
eg. ADB push d:\Test.apk System/app
ADB shell-related commands
Command format: adb [-d|-e|-s {serialnumber}] Shell <shellCommand>
Exit Shell:ctrl + C/exit
To eliminate the cache command:
ADB Shell Rm–r/data/dalvik-cache
Transfer keyevent:
When the customer phone has a hardware keyboard, and the internal phone does not have the corresponding key, you can use the command to send key to the module button
ADB shell input KeyEvent keycode
The keycode of each key can be found in the Keyevent.java class, commonly used KeyCode as follows:
Home:3 Back:4 power:26 menu:82
Transfer text:
ADB shell input text "XXX"
Get all System Properties
Or a property:
ADB Shell Getprop
ADB shell Getprop PropertyName
To set a property on the system:
ADB shell SetProp PropertyName value
eg. ADB Shell SetProp Launcher2.allappsgrid 2d
There are two more good commands are adb shell am and adb shell pm, these two commands under Frameworks/base/cmds;
The AM command is primarily used to manage activity, such as starting, stopping activity (which is used by eclipse to run the activity), and sending intent;
The format is:
ADB shell am START-N package Name/package name + class name (-N class name,-a action,-d date,-m mime-type,-c category,-e Extended data, etc.).
Instance 1:adb shell am start-n com.android.camera/. Camera
Instance 2:adb shell am start-n com.android.contacts/.activities. Peopleactivity Content://contacts/people
PM commands are primarily used to manage the administration of the app package, which is a bit like adding and removing programs from the Control Panel.
ADB shell PM List packages Get what packages are currently installed on the system
Frameworks/base/cmds There is another command, as follows:
Dumpstate
Dumpsys
Ime
Input
Installd
Service
ServiceManager
Surfaceflinger
System_server
Dumpsys command
This view system information, use or more.
Dumpsys [Options]
Meminfo Display Memory Information
Cpuinfo Displaying CPU information
Account Displays accounts information
Activity shows all the activities information.
window shows the keyboard, Windows, and their relationships
WiFi Display WiFi information
All the other orders, I'm not going to start here.
Debug related
ADB logcat command format: adb logcat [–b <buffer>] [–v <format>] > Log_file.txt
Buffer:radio/events/main default is Main
Format:time-display the date, invocation time, Priority/tag, and PID of the originating process.
Brief-display Priority/tag and PID of originating process (the default format).
Process-display PID only.
Tag-display the Priority/tag only.
USB connection device fetches main log
ADB logcat–b main–v time > Main.txt
ADB logcat–v time >main.txt-b default is main
USB connection device Crawl events log
ADB logcat–b events–v time > Events.txt
USB connection device Crawl radio log
ADB logcat–b radio–v time > Radio.txt
USB connection device Crawl kernel log
adb shell cat/proc/kmsg > Kernel.log
Set the filter for the log output
Each Android log has a tag and a priority associated with it
Tag:public static final String tag= "xxx";
Priority:v (Verbose-lowest), D (Debug), I (Info), W (Warning), E (Error), F (Fatal),
S (Silent-highest,nothing is ever printed)
Set the command format for log filter: adb logcat tag:priority ...
Log all W and W priority above
ADB Logcat *: W
Only info and above log information of tag Activitymanager is typed.
Only log with tag Activitymanager is typed
ADB logcat activitymanager:i *:s
ADB logcat activitymanager:* *:s
Typing Activitymanager info and above log information and MyApp Debug and above log information
ADB logcat activitymanager:i Myapp:d *:s
Bugreport related
Bugreport will print out information such as Dumpsys,dumpstate and Logcat
ADB bugreport <log_file_path> Displays all the information in the bug report
ADB bugreport > Bugreport.txt store bugreport in TXT file
Memory related
Get the ranking of all process use memory in the system
ADB Shell Procrank >procrank.txt
Get the memory usage of a process
Get PID for all process of the system via ADB shell PS
Get all the process of the system without PID
ADB shell Dumpsys meminfo pid or
adb shell Dumpsys meminfo packagename
adb shell Dumpsys meminfo >dumpsys_meminfo.txt
Get total system memory and Remaining amount and other information
ADB shell Cat Proc/meminfo >proc_meminfo.txt
Get the maps of a process
ADB shell Cat Proc/pid/maps >maps.txt
Get the smaps of a process
ADB shell Cat Proc/pid/smaps >smaps.txt
Some common commands for capturing logs from other modules:
adb shell Dumpsys window >win.txt see which Windows are currently in the system
ADB shell Dumpsys Activity activities > Activity_stack_info.log view current system activity stack
adb shell Dumpsys Surfaceflinger >surfaceflinger.txt
adb shell Dumpsys gfxinfo >gfxinfo.txt Use this line of command to see all process use Hwui
Open the broadcast related log switch in AMS: ADB shell dumsys activity log BR on
Please confirm the version of GPU driver with the following command:
ADB Shell Cat/proc/pvr/version >gpu_version.txt
The following content in the internal fast grab log verification when it is more useful to crawl the desired log is more convenient.
To catch log, use adb logcat–v time Tag1: Priority level Tag2: Priority ... > Log.txt on it.
Using the Logcat command
The general usage of the command Logcat to view and track the system log buffers is:
[ADB] logcat [<option>] ... [<filter-spec>] ...
The filter and command options are described below, and details can be found in the listing of logcat command option.
You can use the Logcat command to view the log output in the development machine by using the remote shell:
$ adb Logcat
If you are using the command directly in the remote shell:
# Logcat
Filtering log output
Each log message has a tag and priority associated with it.
A token is a short string that identifies the source of the original message (for example, "View" originates from the display system).
The priority is the following character, in order from low to High:
V-Detail (lowest priority)
D-Debug
I-Information
W-Warning
E-Error
F-Critical Error
S-no record (highest priority, nothing will be recorded)
By running Logcat, you can get a list of tags and priorities used in a system, the first two columns of the observation list, and the format given is <priority>/<tag>.
Here is a log output message, the priority is "I", the token is "Activitymanager":
I/activitymanager (585): Starting activity:intent {action=android.intent.action ...}
If you want to reduce the content of the output, you can add filter expression restrictions, the filter can limit the system to output only the tag-priority combination of interest.
The format of the filter expression is tag:priority ..., where tag is the token, priority is the minimum precedence, and the token identifies all messages that are greater than or equal to the specified priority level to be written to the log. You can also provide several such filters in a filter expression, separated by a space.
The example given below is only the output labeled "Activitymanager" and the priority is greater than or equal to "Info" and the log labeled "MYAPP" with a priority greater than or equal to "Debug":
ADB logcat activitymanager:i Myapp:d *:s
The final *:s of the above expression is used to set the log priority for all tokens to S, which ensures that only logs labeled "Activitymanager" and "MyApp" are output, and using *:s is a recommended way to ensure that the output conforms to the specified filter settings. This makes the filter a "white list" of log output.
The following expression shows all logs with priority greater than or equal to "warning":
ADB logcat *:w
If you are running LOGCAT on a development computer (as opposed to running a transport shell), you can also set the default filter expression through the ANDROID_LOG_TAGS environment variable:
Export android_log_tags= "activitymanager:i Myapp:d *:s "
Note that if you run logcat in a remote shell or using the ADB Shell logcat command, Android_log_tags will not be exported to the emulator or mobile device.
Control log Format
Log messages have a number of metadata fields beyond the mark and priority, which can be controlled by modifying the output format to control the output, and the-v option, together with the contents listed below, controls the output field:
brief-Show priority/tag and PID of the original process (default format)
process-Show only Process PID
tag-only show priority/tag
thread-Show only processes: threads and priorities/tags
raw-Display the original log information, no other metadata fields
time-display date, call time, priority/tag, PID
long-display all metadata fields and separate message contents with blank lines
You can use-V to start Logcat to control the log format:
[ADB] logcat [-v <format>]
For example, use the thread output format:
ADB logcat-v Thread
Note You can specify only one format in the-v option.
viewing alternative Log buffers
The Android log system maintains multiple loop buffers for log messages, and not all messages are sent to the default buffers, and to view these additional buffers, you can use the-B option, which is the buffer you can specify:
radio-viewing buffer messages that are contained in a wireless/phone-related
events-viewing event-related messages
main-Viewing the primary buffer (default buffer)
Use of the-B option:
[ADB] logcat [-b <buffer>]
For example, view the radio buffer:
ADB logcat-b Radio
1. Export Log to SD card
ADB logcat-d-f/sdcard/log.txt
2. Export log to local PC
ADB logcat-v Time Activitymanager:i Myapp:v-V > Log.txt
Use of common commands in ADB