android adb study notes (a)

A, adb Overview

  adb (Android Debug Bridge), Android Debug Bridge platform, a bridge between Android phone and PC, and can be managed through adb, simulator operation and equipment, such as installing software, hardware and software to view the device parameters, system upgrades, run shell commands.

  Android for mobile end of the test, adb command is a very important point must be common adb commands by heart, will bring great convenience for Android testing, many of which command will be used for automated test scripts among.


The main features are:

  • Operation of equipment shell (command line) 
  • Port mapping management device or simulator 
  • Upload / download files between computers and devices 
  • Apk local to the simulator software installation or device android

adb is a C / S command-line tool framework, mainly consists of three parts:

  • Running on the PC side of the Client: It can be installed by Android application, unloading and debugging
    • In Eclipse ADT, DDMS in the SDK Tools directory, Monitor and other tools are used in the same way adb capabilities to interact with your Android device.
      PC side of the mobile assistant, such as 360 mobile assistant, pea pods, treasure and other applications, easy to install third-party applications in addition to its other functions, can basically go through the complete adb command proposed here 测试人员try not to install this type of phone on the computer assistant, because it comes with adb program may conflict with adb program under the Android SDK, 5037 the port is occupied, making it impossible to connect to the device when using the adb command
  • Running on the PC side Service: its management client to connect adb daemon on Android devices
    • Adb after the service starts, Windows may find adb.exe this process in Task Manager
  • Adb daemon running on Android devices
    • Execution  adb shell ps | grep adbd , can be found in the background process, windows use  findstr alternative grep

 


Download adb kit, including adb and drivers:  official website to download


 

Two, adb install

Preparing the environment: mac

1, the homebrew installation (omitted)

2, install adb

brew cask install android-platform-tools

 3, run adb

Enter adb, adb help information at this time will appear, indicating that the installation was successful adb

adb 或 adb help

 

Three, adb command Introduction

In the development or testing process, we can manage multiple devices through adb, its general format is:

adb [-e | -d | -s <device serial number>] <subcommand>

 Here are some commonly used commands:

  • adb devices get a list of equipment and equipment status
  • adb get-state acquisition device status
    • There are three state devices
      • device: device normally connects
      • offline: abnormal connection device unresponsive
      • unknown: the device is not connected
  • adb kill-server, adb start-server end adb service, start adb service, commonly used with two commands
    • Usually abnormal connection, the normal use of the device is not listed adb devices, abnormal state of the device using kill-server, and heart cloud start-server restart service
  • adb logcat log printing system of Android, this individual can come up with in terms of reference materials
  • adb bugreport print dumpsys, dumpstate, logcat output, and it is used to analyze the error
    • Output more content, it is recommended to redirect to a file
      • adb bugreport > d:\bugreport.log
  • adb install install the application, use the -r option to cover installation
    • If you need to install the windows apk contain Chinese name, it is necessary to modify the adb, adb Baidu can be found to make changes to support the Chinese command apk, please search on their own
  • adb uninstall 卸载应用,后面跟的参数是「应用的包名」,请区别于「apk文件名
    • '-k' means keep the data and cache directories,-k选项,卸载时保存数据和缓存目录
  • adb pull 将Android设备上的文件或文件夹复制到本地
    • 例如复制sdcard下的pull.txt文件到D盘:
    • adb pull sdcard/pull.txt d:\
    • 或者重命名:adb pull sdcard/pull.txt d:\rename.txt
      • 注意需要root权限
  • adb push 推送本地文件至Android设备
    • 例如推送D盘下的push.txt至sdcard
      • adb push d:\push.txt sdcard/
      • sdcard后面的斜杠不能少,否则会出现如下错误
      • failed to copy 'push.txt' to 'sdcard':Is a directory
  • adb root,adb remount 只针对类似小米开发版的手机使用,可以直接以这两个命令获取root权限,并挂载系统文件为可读写状态
  • adb reboot 重启Android设备
    • bootloader,重启设备,进入fastboot模式,同adb reboot-bootloader命令
    • recovery,重启设备,进入recovery模式,经常刷机的同学比较熟悉这个模式
  • adb forward 将宿主机上的某个端口重定向到设备的某个端口
    • adb forward tcp:1314 tcp:8888
    • 执行该命令后所有发往宿主机1314端口的消息,数据都会转发到Android设备的8888端口上,因此可以通过远程的方式控制Android设备
  • adb connect 远程连接Android设备
    • 手机、pc处于相同网络下,手机root,安装应用adbWireless,启用应用后点击界面中间的按钮
    • 接着运行 adb connect 192.168.1.102 , 即可通过无线的方式连接手机,缺点是速度比较慢

 

Guess you like

Origin www.cnblogs.com/helloTerry1987/p/11028958.html