Adb environment construction and use

1. Introduction

The full name of adb (Android Debug Bridge), it is a common command line tool, it can be used as a bridge between Android and PC, so adb is also called Android Debug Bridge, users can use adb on the computer to fully monitor the Android device Operations, such as installing and debugging applications, operating file transfers, etc.

2. Environment construction

  1. Installation method 1: Install through homebrew

    1. Install homebrew (terminal input command)

      • /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
        

      • Enter 1 and press Enter, there will be a prompt after the installation is successful

    2. Install adb through brew (terminal input command)

      • brew install android-platform-tools

    3. Restart the terminal, check and start adb (see step 3 for device connection)

  2. Installation method 2: Download the platform-tools package by yourself and configure environment variables

    1. Visit android dev tools , download platform-tools package

    2. Unzip to any path after downloading

    3. Configure environment variables, take bash as an example (terminal default)

      • enter the configuration file

        • vi ~/.bash_profile

      • Add environment variables

        • export PATH=${PATH}:/Users/apple/Library/Android/sdk/platform-tools

          Where " /Users/apple/Library/Android/sdk/" is replaced by the path you just decompressed

          Where "platform-tools" is replaced with the folder name just unzipped

    1. Restart the terminal, or source ~/.bash_profile to take effect configuration

      • Verify adb (check the third step for device connection)

3. Device connection

  1. Open developer options
  2. Turn on USB debugging
    1. [Xiaomi/Redmi] USB installation and USB debugging (security settings) need to be turned on; the former is used to install apk through adb, and the latter is generally used for UI automation;
    2. [Close the installation confirmation pop-up window] When some devices are installed through adb, there will be a confirmation pop-up window on the terminal. In the developer options, turn off the USB installation verification (via USB verification application);
    3. Data cable connection mode: for most devices, the default file transfer mode can be selected. In the developer options, there is a "charge only" mode that allows ADB debugging. If the default connection mode of the device is not charging mode, just turn off this option; or adjust the default connection mode;

      

  3. Allow USB debugging popup
    • When we open the settings according to the above steps, connect the device with a data cable that can transmit data, and the pop-up window will pop up on the device; check Allow all, click OK
    • If it does not pop up, you can enter adb devices in the terminal to see if it pops up;
    • If it is accidentally turned off, unplug the cable and plug it in again;

     
  4. Check if the connection is successful in the terminal
    1. Enter adb devices
    2. connection status information

      1. device status: This status indicates that the device or emulator has been connected to the adb server. But this state does not mean that the physical mobile device or emulator has been started and can be operated, because the Android system will first connect to the adb server when starting, but after the android system is started, the device or emulator is usually in this state.

      2. Unauthorized state: This state means unauthorized, you need to check the configuration of the above developer options.

      3. offline state: This state indicates that the device or emulator is not connected to the adb server or is not responding.

      4. no device state: This state indicates that no physical device or emulator is connected.

    3. specified device execution
      1. When multiple devices are connected, adb devices will return the serial numbers of all connected devices; if you only need to operate the specified device, you can use "-s <serial-number>" to operate, serial-number is the serial number obtained earlier ;
  5. [Port 5073 Conflict] When we use adb, it is required not to install other applications that interact with Android devices on the computer, such as App Store, Pea Pod, xx Mobile Assistant, etc.; if they have been installed, even if they are not started, these applications will run in the background The process with adbSevier occupies port 5073;
    1. Solution 1: Uninstall such apps
    2. Solution 2: Close the process occupying adb
    3. Solution 3: Change adb port  adb -P <port> start-server

Four, common commands

  1. [Get device details] adb devices -l
  2. 【Install application】adb install <apk>
  3. [Overwrite installation/force installation] adb install -r <apk>
  4. [Display the list of installed applications] adb shell pm list packages

  5. parameter show list

    none

    all applications
    -f Display the apk file associated with the application
    -d Only show disabled apps
    -e Only show enabled apps
    -s Show only system apps
    -3 Show only third-party apps
    -i Show the installer of the application
    -u Include uninstalled apps
    <filter> contains  <filter> the string

  6. [View the currently running Activity] adb shell dumpsys activity activities | grep "mResumedActivity"

  7. [Uninstall application] adb uninstall <package_name>
  8. [View application details] adb shell dumpsys package <package_name>
    • You can get Activity Resolver Table, Registered ContentProviders, package name, userId, paths such as installed file resource codes, version information, permission information and grant status, signature version information, etc.
  9. [View application installation path] adb shell pm path <package_name>
  10. [Start the application/call up the Activity] adb shell am start [options] <intent>
    1. [Can be used to trigger deeplink jump] adb shell am start deeplink_url
    2. [Small extension] Through the Utools tool I shared before, you can also convert the URL into a QR code, and scan the code to trigger a deep link to jump to the
      uTools official website-a new generation of efficiency tool platform
  11. [Download the specified file from the simulator/device to the computer] adb pull <remote> [local]

  12. [Upload the specified file from the computer to the emulator/device] adb push [local] <remote> 
  13. [Check whether the mobile phone cpu is 64-bit or 32-bit] adb shell getprop ro.product.cpu.abi 
  14. [View an application log] adb logcat | grep "<package_name>"
  15. 【Enter mobile phone system】adb shell
  16. [Input the test copy into the phone input box] adb shell input text "text" 

Five, commonly used to expand knowledge

Efforts can only pass, hard work can be excellent~

Guess you like

Origin blog.csdn.net/yaoliang_cui/article/details/127846374