Summarize some commonly used adb commands
introduction
- In Android development, we sometimes need to use some commands to help us locate and solve problems more efficiently. This article will introduce some hidden but very useful commands that can help us quickly find problems.
basic command
-
For example, some more commonly used commands, such as cd rm cp, will not be introduced. Here are a few commands that are not commonly used and will greatly improve development efficiency after understanding.
-
cat
-
This naming phrase is used to view the file. Now I push a config.xml file to data/local/tmp, which can be viewed with the cat command.
shell@6753_doov_legend:$ cat config.xml <?xml version="1.0" encoding="UTF-8"?> <nqtestdata> <country>CN</country> <mcnc>604123</mcnc> <!--<lat>39.213123<lat> <lon>116.123123<lon> <networkcountry>123123</networkcountry> <networkmcnc>123123</networkmcnc>--> <debug>true</debug> <writeLog>true</writeLog> <serverType>VRF</serverType> </nqtestdata> shell@6753_doov_legend:$
-
This command can also be filtered in combination with the grep command. For example, I now use the grep command to filter the debug items in the above files.
shell@6753_doov_legend:$ cat config.xml |grep debug <debug>true</debug> shell@6753_doov_legend:$
-
Common adb commands
-
adb install [-l] [-r] [-s] file
- [-l] lock the program, install
- [-r] Reinstall the program, save data
- [-s] install to sdcard
-
adb uninstall [-k] package_name
- [-K] Unclear data, uninstall
-
pm clear package_name
- Clear the data of the specified package name
-
pm install
- Corresponding to adb install
-
pm uninstall
- Corresponding to adb install
-
adb shell dumpsys
-
adb shelll dumpsys activity top
- 用于查看当前运行应用的的信息 C:\Users\isaac>adb shell dumpsys activity top TASK com.aliyun.homeshell id=1 ACTIVITY com.aliyun.homeshell/.Launcher 296c7d6c pid=1867 Local Activity 22a2410f State: mResumed=true mStopped=false mFinished=false mLoadersStarted=true mChangingConfigurations=false mCurrentConfig={1.0 ?mcc?mnc zh_CN ?layoutDir sw360dp w360dp h615dp 480dpi nrml long port finger -keyb/v/h -nav/h s.6colorMap={header_color=-16731727, dark_mode=0, hw_highlighted_text=1711321521, hw_color_primary_disabled=-16731727, h eader_widget_color_pressed=-2500135, hw_color_primary=-16731727, hw_color_primary_dark=-16739694, header_text_color_unch ecked=-2130706434, dyncolor_mode=1, hw_dialog_ok_button_text_disable=1711321521, header_divider=-13648194, header_text_c olor=-2, header_widget_color_normal=-2, header_widget_color_disable=-2}} FragmentManager misc state: mActivity=com.aliyun.homeshell.Launcher@22a2410f mContainer=android.app.Activity$1@30c7b48c mCurState=5 mStateSaved=false mDestroyed=false ViewRoot:略 //可以看到当前应用的基本信息已经出来了,下面还包括整个View的层级
-
-
adb shell dumpsys package <package_name>
-
You can view the details of the application with the specified package name (equivalent to the content in the AndroidManifest.xml of the application)
C:\Users\isaac>adb shell dumpsys package com.android.settings Activity Resolver Table: Full MIME Types: ... Base MIME Types: ... Schemes: printjob: ... package: ... Non-Data Actions: android.net.wifi.PICK_WIFI_NETWORK: 2ef8f99e com.android.settings/.Settings$WifiSettingsActivity android.settings.SHOW_REGULATORY_INFO: a449c7f com.android.settings/.RegulatoryInfoDisplayActivity ...
simply list a few
-
-
adb shell dumpsys meminfo <package_name/pid>
-
You can view the memory information of the specified process name or process id
** MEMINFO in pid 20677 [com.android.settings] ** Pss Private Private Swapped Heap Heap Heap Total Dirty Clean Dirty Size Alloc Free ------ ------ ------ ------ ------ ------ ------ Native Heap 0 0 0 0 12288 6287 6000 Dalvik Heap 3775 3072 0 0 20323 19251 1072 Dalvik Other 357 252 0 0 Stack 156 156 0 0 Ashmem 8 0 0 0 Other dev 6 0 4 0 .so mmap 718 120 0 0 .apk mmap 399 0 240 0 .ttf mmap 117 0 0 0 .dex mmap 1482 0 1052 0 .oat mmap 930 0 12 0 .art mmap 932 540 0 0 Other mmap 27 4 0 0 EGL mtrack 10880 10880 0 0 GL mtrack 12620 12620 0 0 Unknown 4088 4000 0 0 TOTAL 36495 31644 1308 0 32611 25538 7072 Objects Views: 103 ViewRootImpl: 1 AppContexts: 3 Activities: 1 Assets: 4 AssetManagers: 4 Local Binders: 21 Proxy Binders: 23 Parcel memory: 3 Parcel count: 14 Death Recipients: 2 OpenSSL Sockets: 0 SQL MEMORY_USED: 0 PAGECACHE_OVERFLOW: 0 MALLOC_SIZE: 0
-
-
adb shell dumpsys dbinfo <package_name>
- You can view the database storage information of the specified package name application (including stored SQL statements)
-
adb shell dumpsys activity services <package_name>
- See what services the app has started
-
adb pull
-
Put the files on the device to the local
-
eg:adb pull /sdcard/tmp.txt D:\
The command is simple, I won't say more, but you may encounter file permission problems during operation, and you can change the permissions with chmod.
-
-
adb forward [(remote side)protocol:port number] [(device side)protocol:port number]
-
Port forwarding for devices
adb forward tcp:23946 tcp:23946 adb forward tcp:8700 jwdp:1786
This command is very useful for us when debugging, especially in IDA debugging.
-
-
adb jdwp
-
View the process ID of the application that can be debugged on the device
adb jdwp
This command may not have many uses, but it is still useful for debugging. This command can be ignored.
-
-
adb logcat |findstr pname/pid/keyword
-
View current log information
adb logcat -s tag |findstr <package_name> adb logcat -s ActivityManager | findstr com.android.settings I/ActivityManager( 848): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.android.settings/.Settings bnds=[828,1302][1026,1542]} from uid 10024 on display 0
This command is familiar to everyone, and it is also a top priority. Some students may be curious why AS is not used to view logs, but sometimes AS cannot satisfy us. For example, we want to open multiple log windows. At this time, we can open more than one log window. A cmd window can use this command to view log information. The most used is the -s parameter, you can directly view the corresponding tag log information, you can use findstr to filter the information:
- You can also filter by grep when entering the adb shell
-
-
am start -n [package name]/[package name].[activity name]
-
start an application
am start -n com.android.browser/com.android.browser.BrowserActivity
Note: You can start the application in debug mode: am start -D -n .... Especially when we decompile and debug the application, you may need to start the application in debug mode
-
-
am startservice -n [package name]/[package name].[service name]
-
start a service
am startservice -n com.android.traffic/com.android.traffic.maniservice
Similar to the above command, start the service
-
-
am broadcast -a [broadcast action]
-
send a broadcast
am broadcast -a android.NET.conn.CONNECTIVITY_CHANGE
Similar to the above command, to send a broadcast, sometimes we define a broadcast, we may need to test, we can use this function to simulate sending a broadcast.
-
-
netcfg
-
View the ip address of the device
Sometimes I want to check the IP address of the device, and it is too laborious to go to the setting page. You can use this command directly.
-
aapt dump xmltree [apk package] [resource file xml to be viewed]
-
View the information in the apk and edit the apk package
aapt dump xmltree demo.apk AndroidManifest.xml
-
-
dexdump [dex file path]
-
You can view the trust information of a dex file
dexdump D:\classes.dex
-
-
cat /proc/[pid]/maps
- View the memory loading of the current process, and view the memory mapping information of the current process, such as which so files, dex files, etc. are loaded:
-
cat /proc/[pid]/status
- View the status information of the current process
-
cat /proc/[pid]/net/tcp/tcp6/udp/udp6
- Get the port number information used by the current application