ADB commands are very easy to implement application installation, uninstall, device management, and other operations, and can get rid of the annoying USB limitation, in the business of three companies debugging is an essential tool, so Android developers must master the basic skills. This article introduces some of the ADB directives that Android developers use to debug their work. On a Mac, you can install iTerm2 and set related functions, such as theme color, syntax highlighting, and command history. Computer configuration command line may refer to: www.cnblogs.com/easonscx/p/…

1. View the connected device:

adb devices

Result: List of devices attached

4c00141601d1477230e   device

9YS0220306003367     device

2. Connecting devices (within the same LAN) :

Adb connect device IP eg: ADB connect 172.17.231.62 Successful: Connected to 172.17.231.62:5555

Note: Some phones or devices may be denied access to IP directly through ADB. You can connect the phone via USB first, Android Studio plug-in (Wifi ADB ULTIMATE), and then ADB.

3. Install APK (apply APK) :

adb install D:\app-debug.apk

If there are multiple devices, as in the case of the first command, use the following:

adb -s SH0A6PL00243 install D:\app-debug.apk

The same is true for multiple devices when executing other commands

4. List the package names of all apps installed on your phone:

adb shell pm list packages

Eg: adb -s 172.17.231.62:5555 shell PM list packages

5. Install system applications: System applications are applications under the system/app directory, and the installation only needs to push the APK under the system/app: 1. Root adb -s device root eg: adb -s 172.17.231.62:5555 root Adbd is already running as root 2. Adb -s device shell remount eg: adb -s 172.17.231.62:5555 shell remount succeeded: [libfs_mgr]__mount(source=/dev/block/dm-3,target=/mnt/scratch,type=f2fs)=0: Success

3. Push the application under system/app: adb -s device push demo.apk /system/app eg: The adb -s 172.17.231.62:5555 push/Users/pengliang/Library/Containers/com. Tencent. WeWorkMac/Data/Library/Application \ Support/WXWork/Data / 1688854033882050 / Cache/File / 2021-01 / Camera2 Camera2. Apk/system/app success: /Users/pengliang/Library/Containers/co... Ed. 1.4 MB/s (4802286 bytes in 3.188s) Displays the push progress and package sizeCopy the code

Adb -s device ls system/app eg: adb -s 172.17.231.62:5555 ls system/app 000041ed 00001000 495c0780 WallpaperBackup 000041ed 00001000 495c0780 CustomerFactoryTest 000041ed 00001000 495c0780 NfcNci

7. Uninstall common applications directly:

adb uninstall

Adb -s device shell rm -rf /system/app/demo.apk eg: Adb -s 172.17.231.62:5555 shell rm system/app/ camera2.apk

Result: Check whether the uninstallation is successful by querying the system application list

9. Start the app:

adb shell am start -n /.ui.SplashActivity

10. Forcibly stop the application:

adb shell am force-stop

11. Check the Android version:

Adb shell getProp ro.build.version.release eg: adb -s 172.17.231.62:5555 shell getprop ro.build.version.release Success: 10

Other rarely used commands: 1. Save data and cache files and reinstall APK, also called forced installation:

adb install -r D:\app-debug.apk

2. Install APK to SD card:

adb install -s D:\app-debug.apk

3. Uninstall app but keep data and cache files:

adb uninstall -k

4. Clear application data and cache:

adb shell pm clear

5. View logs:

adb logcat

Add a filter for silky smoothness:

adb logcat | grep -i “^E.MyApp”

Description: grep whitelist mode, tag matching “XXX”,

“^Exxx” is Error, and the end of “^.MyApp” matches the tag of MyApp. -i ignores case.

Grep -v Indicates the blacklist mode.

Such as:

adb logcat | grep -v “^.. MyApp|^.. MyActivity” adb logcat | grep -vE “^.. MyApp|^.. MyActivity” # use egrep without escaping

6. Restart:

adb reboot

7. Obtain serial number:

adb get-serialno

emulator-5554

8. View the device model:

adb shell getprop ro.product.model

Android SDK built for x86

9. Check the screen resolution:

adb shell wm size

Physical size: 480×800

10. Check screen density:

adb shell wm density

Physical density: 480

11. Uploading files from your computer to your phone:

Adb push < local path >

12. Copy files from your phone to your computer:

Adb pull < adb pull >

  1. Resolve ADB connection instability:

adb start/kill server

You can kill-server and then start-server to ensure that the server process is started. Can often solve the problem.

14. Screenshots:

adb shell screencap /sdcard/screen1.png

15. To see a lot of information system (Windows, the activity, the stack, the information such as wifi) :

adb shell dumpsys -h

A useful command is,

Adb shell dumpsys meminfo

You can see if the current project has a memory leak,

The practical way is to go into the app, and then exit as normal,

If the number of references of any component is not zero, it is a leak. You can dump the memory fragment file hprof for analysis. As for locating memory leaks completely, I will analyze them in the next article.

16. Obtain power consumption information:

Obtain the power consumption information of the whole equipment:

adb shell dumpsys batterystats | more

Get the power consumption information of an APK:

adb shell dumpsys batterystats | more

You can use a Python script historian. Py to form visual HTML to analyze power consumption. I’ll share how to use it in future performance optimizations.

If you want to read more ADB commands, we recommend a complete and detailed guide to ADB usage.

At the end of the article, some common pits and solutions are recorded:

1. Adb (5037) port is occupied

Solutions:

A. Step one, look at the service port

adb nodaemon server

cannot bind ‘tcp:5037’

B. Step 2 check the usage of port 5037

netstat -ano | findstr “5037”

  TCP    127.0.0.1:5037        0.0.0.0:0              LISTENING      8516

  TCP    127.0.0.1:5037        127.0.0.1:59163        TIME_WAIT      0

  TCP    127.0.0.1:5037        127.0.0.1:59164        TIME_WAIT      0

  TCP    127.0.0.1:5037        127.0.0.1:59167        TIME_WAIT      0

C. Step 3 View the process name of thread ID8586

  tasklist | findstr “8516”

Sjk_daemon 8516 Console 13,071 K

Oh, sjk_daemon is using adb ports.

D. In step 4, check the process ID corresponding to the process name

  tasklist

Image Name                    PID Session Name        Session#    Mem Usage

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

System Idle Process              0 Services                  0        24 K

System                          4 Services                  0      1,128 K

Sjk_daemon 963 Console 1 3,071 K

Tasklist. exe 1260 Console 1 5,856 K

E, step 5: Kill the process:

taskkill /f /pid 963

If this command indicates no permissions, go to the Process window in The Windows Task Manager window, find the process, and kill it.

Run ADB Devices again and there is no problem.

adb devices

9dk7f482396a371j        device

Or restart:

adb kill-server

adb start-server