1.1 ADB Introduction
ADB (Android Debug Bridge) is a tool that comes with the Android SDK.
ADB is used to connect Android devices and PC-side bridge, through the ADB tool, the user can be on the PC side of the mobile phone for full operation.
Android is originally designed to use a tool such as ADB to assist developers in the development of Android applications faster and better debugging apk, so the ADB has a loading and unloading apk, copy push files, view device hardware information, view the application occupies resources, Perform functions such as shell commands on the device.
ADB can cross-platform, which means that not only in Windows, the Mac/linux platform can be used to use the ADB command, only need to download the configuration of the corresponding platform software package.
The ADB has three components:
Clients (client)
Run on your own computer, you can use the shell to tune up a client
Servers (server)
Run in the background of the computer, responsible for managing client and Damon Communication
Daemon (Damon)
Running in the background of an emulator or Android device
The ADB tool is located in the Platform-tools directory under the SDK directory with three files related to ADB:
We had already deployed the ADB before we built the automated environment, and we used it directly in the DOS environment of Windows (by running input cmd), so let's start by introducing how ADB is used.
TIPS:ADB are all commands to operate Android devices.
1.2 ADB common Command series
ADB--help
View Help Manuals
ADB devices
Check the Android device connected to the PC, this is our most frequently used command, here is one thing to note:
The Android emulator and the real Android device connection are different if you are using the Genymotion simulator because the emulator has been set up
So Genymotion Simulator will automatically help you load the connection adb, we can detect it directly through the ADB devices command, but if you are using the night God/Hippocampus play simulator, these will not automatically help you connect.
So we need to manually connect via command ADB Connect, such as the night God is adb connect 127.0.0.1:62001
(The 127.0.0.1 here means the local IP address, any computer has this address, and 62001 represents the port number of the night God Simulator.)
If you are the hippocampus play simulator, then the port number is changed to 26944.
If it's a real Android device (Mobile/tablet):
1. Need to make sure your phone is connected to the computer via USB cable
2, through the driver software, drive the wizard/drive life, etc., will your Android phone driver installed
3, go to the phone, find settings--about mobile phone--click Five next version number, and the corresponding developer options open (note: Due to different phone models, such as Xiaomi, Meizu, Huawei These, may open the way slightly different, if not clear, Baidu how to open their own mobile phone developer options)
4. Exit to the previous level menu, go to developer options, find the USB debug simulator to open it
5, there is a final step, generally will come out a confirmation Debugging dialog box, we also need to tick, or the ADB command can not be used
ADB shell
Login to the device shell (the command line HMI), in the current environment can be used to many Linux-related commands, such as: CD, LS, CP and so on, equivalent to the remote execution of the command
ADB pull < Phone path > < computer path >
Pull the information from the phone to the local computer, the mobile phone path through the ADB shell into the shell environment, through the CD, LS these commands to find the corresponding files, such as the QQ APK pulled into the test directory under the D disk
ADB push < Native path > < phone path >
Push information from the local to the phone, such as
ADB install *.apk
In order to get the address of the APK installation package, you can simply drag the apk to the cmd window to get it and return to success to indicate that the installation was successful.
ADB install-r *.apk
Keep data and cache files, reinstall APK
ADB Shell Dumpsys Activity | Find "Mfocusedactivity"
Check the foreground app package name and class name (here's a general overview of what the package name is: Android system gives the app's identity)
ADB Uninstall < package name >
Uninstall an app, you need to add the corresponding package name later
ADB uninstall-k < package name >
Uninstall apps but keep data and cache files
ADB kill-server
Termination of ADB services
ADB start-server
Start the ADB service, usually with Kill-server to restart the ADB service when problems occur with the ADB
ADB shell PM List Packages
List all package names in the current system
-s lists the system apk path and package name
-3 List User apk and package name
ADB logcat
Crawl Android logs, this is also a very useful command for us, through the Logcat log, in the app exception, such as crash/no response to this, can be located in the Logcat inside the corresponding information
ADB connect/disconnect
Remote debugging via WiFi, we can not need to connect the phone to the computer via USB cable, but there are the following considerations:
1. Make sure that the phone and computer are in the same network (the same router that is connected)
2, advance through ADB tcpip 5555来 to determine the port number of the communication
3. Connect via ADB Connect plus the IP address of your own phone
If you want to cancel the connection, use the ADB disconnect command directly
App Automation Test Essentials for ADB use