ADB installation and common commands

I. Overview

adb (Android Debug Bridge), the Android platform debugging bridge, is a bridge connecting Android phones and PCs. Through adb, you can manage and operate emulators and devices, such as installing software, viewing device software and hardware parameters, system upgrades, and running shell commands.

2. Installation and use

1. Install Android Sdk on the PC side and configure environment variables to ensure that adb can be used normally

       Example: Install the apk package on the computer to the phone through adb install

       (1) Download the mac version android-sdk

       (2) Configure the environment variables of sdk

       1. Open the shell "terminal tool", such as the terminal tool or iTerm that comes with the mac, and the following places that need to be used are represented by "shell terminal";

        2. Edit the bash_profile document by entering the following command in the shell terminal: vi ~/.bash_profile, if this document has not been created before, it will be automatically generated;

        3. Press the letter i to enter the editing state of the document, and enter export PATH=${PATH}:x/platform-tools (where x refers to the path where the android-sdk file was decompressed before);

        4. The way to get the x folder path can be in the shell command line first cd to the directory where the android-sdk folder is stored, and then enter pwd to get the path, such as storing the folder in the download folder, the general The path is /Users/Downloadsandroid−sdk−macosx

        5. After entering the export PATH command, press Esc in the upper left corner of the keyboard to exit the editing state, and at the same time enter: wq to save the edited content;

        6. Enter source ~/.bash_profile in the shell command line to make the configuration take effect;

        7. Check whether the configuration is correct. You can enter adb on the command line. If the interface does not display an error and you can see the information of Android Debug Bridge version xx, it means that the configuration is successful (as shown in the figure below.)

(3) Install via adb install

2. The mobile phone should be connected to the PC with a data cable, and the mobile phone should open the developer options and usb debugging mode (here, the redmi mobile phone needs to click all the parameters continuously to open the developer options, and then open the usb debugging mode), make sure The adb devices connection is successful (the success page is as shown in the figure below).

 

 

       

3. Combined with examples to see the usage scenarios:

APP Stability Test Example_niuniu0186's Column-CSDN Blog_app Stability Test

Three, adb common commands

db start-server or adb shell to start the adb service

adb kill-server closes the service

adb devices view device number

adb install path install apk

adb uninstall package name uninstall apk

adb get-state device connection status

adb pull Copy files or folders on the Android device to the local computer

adb push Push local files to Android devices

adb bugreport print bugreport report

adb get-product Get the ID of the device

adb shell pm list packages lists all packages

adb shell pm list packages -s system package name

adb shell pm list packages -3 three-party package name

adb shell dumpsys cpuinfo View the current mobile cpu usage

adb shell dumpsys cpuinfo - package name to view the current app cpu usage

adb shell getprop/findstr dalvik View native memory usage

adb shell dumpsys meminfo + package name to view the current app memory usage

adb shell dumpsys activity / findstr “mFocusedActivity” View the package name and startup items of the current app

adb locat View phone logs

logcat -v time process >C:/log/aa.txt Print the log and save it to this machine

adb -s device name logcat -v time process >C:/log/aa.txt specifies the device to print

adb devices #View connected devices

adb -s cf27456f shell # Specify the command to connect the device

adb install test.apk # Install the application

adb install -r demo.apk #Install apk to sd card:

adb uninstall cn.com.test.mobile #Uninstall the application, you need to specify the package

adb uninstall -k cn.com.test.mobile #Uninstall app but keep data and cache files

adb shell pm list packages #List the package names of all apps installed on the phone

adb shell pm list packages -3 #List third-party application package names except system applications

adb shell pm clear cn.com.test.mobile #Clear application data and cache

adb shell am start -ncn.com.test.mobile/.ui.SplashActivity #start application

adb shell dumpsys package #package information Package Information

adb shell dumpsys meminfo #Memory Usage Memory Usage

adb shell am force-stop cn.com.test.mobile #force stop application

adb logcat #View log

adb logcat -c #clear log cache

adb reboot #restart

adb get-serialno #Get the serial number

adb shell getprop ro.build.version.release #View Android system version

adb shell top -m 10 #View the top 10 apps that occupy memory

adb push <local> <remote> #Copy files from local to device

adb pull <r

Guess you like

Origin blog.csdn.net/weixin_44240224/article/details/123051918