2nd Section Android Device Monitor
Android Device Monitor (ADM) is an important helper for us to dynamically debug the Android app. It provides a lot of dynamic debugging tools and debugging methods. The log debugging described in the previous chapter requires the debug content to be displayed through the ADM's Logcat, and it can also see how the system's memory is being used and how the system CPU is running.
ADM can work in two places:
-
In the Android Studio Integration window: In the window below Android Studio, click Android Monitor to display in Android studio;
In the first box, select the device we want to debug, the second box selects the app we want to debug,
-
ADM runs individually: launched via the Android studio menu bar;
After running independently, like this,
2.1 Logcat function
The logcat is used to view the program output log. We can choose the type of log (verbose debug Info warning error) to filter log.
When selected verbose , Logcat will output all types of log;
When selected debug , Logcat outputs the type log of debug info warning error.
When selected info , Logcat will output log of type info warning error, etc.
When selected warning , the Logcat outputs log of the type warning error, etc.
When selected error , the logcat will output the log of the error and other types;
Sometimes log too much, will affect our judgment, you can customize the filter.
-
Select Edit Filter,
-
Specify the name of the filter, enter the contents of the log containing the keyword,
After Logcat gets the log, it is only the log that matches the keyword in the filter.
There is also a very useful feature to restart ADB. The ADB is sometimes unable to connect to the device for a variety of reasons, and the push button to restart ADB will solve the problem.
2.2 ADM in Android Studio
In the Android studio integrated interface, ADM also provides convenient device screenshots, device video features.
The device screenshot saves the content being displayed on the device to the computer as an image or video.
memoryEnables real-time monitoring of the current size of application memory usage being debugged,
-' CPU ' enables real-time monitoring of the CPU usage of the application currently being debugged,
-' network ' enables real-time monitoring of the usage of currently debugged application networks,
# # 2.3 Independently run ADM in addition to Logcat, the standalone ADM provides more debugging tools. By clicking the ' Add View ' icon on the menu bar, you can add advanced debug windows such as ' DDMS ', ' Hierarchy View ', ' Debug ', ' Pixel Perfect ' to Adm. ' DDMS ' is a very comprehensive debugging tool provided by Google, which can communicate with the Android virtual machine to get the most original debug data. 1. Select the device and application to be debugged; 2. Click on the ' DDMS ' menu bar to launch different advanced debugging functions, ' DDMS ' has many advanced debugging functions: * ' Debug ' function: Connect to ' Debug ' version of the application, you can use the break point, step-tracking static debugging mode; * ' heap ' function: Monitor current memory usage, Manually initiate memory reclamation, save all state of memory allocation to the computer, and use other advanced tools for further analysis to find memory leaks;
* ' Thread ' function: View all threads of the application, get the current running information of the thread;
* ' UI Elemental Analysis ' function: Analyze the UI element layout information of the display interface specified window, help the developer to debug the interface layout; * ' OpenGL trace ' function: Record the information of OpenGL call in the application, these functions are advanced debugging functions, Each one can open a separate topic for in-depth explanation. Because this article is aimed at the classmate is just beginning contact debugging novice, so here is not detailed introduction usage. We will describe each in detail in the advanced chapter of the commissioning. # The 3rd section of the ADB tool adb-android debug Bridge is the core of the Android system Debug. It connects the device to the debug computer at the software level. In the second chapter, many of the functions of the ADM in obtaining information on the device are actually obtained through the ADB. The ADB tool is located in the ' SDK directory \platform-tools\adb '. If you use the default directory installation when installing, then it should be ' c:\Users\ user name \appdata\local\android\sdk\platform-tools\adb ' # # 3.1 for ADB add environment variable for convenient use of ADB tools , we'd better add an ' environment variable ' for it. This way, we just open the ' cmd command line terminal ' and we can use it right away. 1. ' My Computer ' right-click ' Properties ', ' Advanced system settings ', ' environment variable ', select ' Path ' for editing; 2. In the formula bar, enter the path of ADB ' c:\Users\ username \appdata\local\android\sdk\platform-tools\ ', and if there are other paths before the entry, use '; ' to separate; 3. Restart the computer--connect on the phone, start ' cmd command line terminal ', enter ' adb version ', if you get a similar result, the ADB has been set up;
versionversion1.0.32Revision eac51f2bb6a8-android
cmd命令行终端The Startup method:
- By
Win+R starting the Windows operating system 运行 panel;
- Enter in the panel
cmd , start the Command line window;
3.2 adb common commands
The ADB provides a number of commands to use, listing the usage of several of the most commonly used commands.
3.2.1 ADB devices
List all Android devices that are currently connected to your computer
$ adb devicesListof devices attached192.168.56.101:5555 device356BCJMDUV48 device
3.2.2 ADB Logcat
Output log information on your Android device. The functionality is exactly the same as the Logcat in Android Device manager. The latter is actually leveraging the ADB tools.
Clear the existing log on the device,
$ adb logcat -c
Start output log,
$ adb logcat -v time
The Logcat -v output option controls the display format of the output data. It provides brief process tag raw time threadtime long equal parameters. In most cases, we -v time 'll just have to use this parameter as well.
Get help,
$ adb logcat -h
In fact, ADB Logcat does not have a h command option, but when Logcat does not find the correct command, it will output logcat help information for the user reference.
3.2.3 ADB start-server
Start the ADB tool,
$ adb start-server
3.2.4 ADB kill-server
Stop the ADB tool,
$ adb start-server
3.2.5 adb shell
Log on to your Android device from your computer,
$ adb shellroot@vbox86p:/#
Once you have logged on to the device, you can operate the device directly.
3.2.6 adb Shell Dumpsys
The status information of all system modules on the output device, this output will be very long,
$ adb shell dumpsys
To let us focus on the modules we need, we can further set the name of the module to dump, for example:
$ ./adb shell dumpsys window
Even further:
$ ./adb shell dumpsys window windows
The names of these modules and the Further Keywords (window windows, etc.) can be adb shell dumpsys found in the returned results, which may appear as follows:
......WINDOW MANAGER LAST ANR (dumpsys window lastanr)......WINDOW MANAGER POLICY STATE (dumpsys window policy)......
In parentheses is the type of dump that can be used.
3.2.7 adb Install
Install the app,
-r /Users/User/Desktop/app.5474 KB/s (1182939bytesin0.211s) pkg: /data/local/tmp/app.apkSuccess
-roption indicates mandatory installation-if the app was previously installed, uninstall it and reinstall it, you can not use it, followed by the location of the installation file on your computer.
3.2.8 adb Uninstall
Uninstall the app,
com.anddle.calculatorSuccess
uninstallfollowed by the package name of the program to be uninstalled.
3.2.9 ADB Help
The ADB tool has a number of other features that can be queried for their in-depth, detailed usage by this command.
help
4th section WiFi instead of data line debugging
We usually use a USB cable to connect the device and the computer to debug the program.
Some programs use a USB port, such as a file browser, which lists USB drives that are plugged into the interface.
When debugging such an application, the USB interface is occupied, but the device also has only one USB interface, you can consider using WiFi for ADB debugging.
Using WiFi instead of data cable for program debugging, the ADB tools adb tcpip and commands are used adb connect .
-
Connect your device and computer using the USB cable and enter the following command
5555//5555表示指定的端口号码,可以修改成别的不知名端口
-
Disconnect the USB cable and connect the computer's ADB to the device via the IP address
adb192.168.1.101 //192.168.1.101为android设备在Wifi网络上的IP地址
This completes the setup of WiFi debugging via the command line.
But here's a simpler scenario, using third-party plugins from Android studio ADB WIFI ,
PreferencesPlugins Browse repositories... ;
- Enter in the search field
ADB WIFI ;
- Select Install
plugin ;
- Restart Android studio on the go;
Later, when you want to use WiFi debugging,
- Connect devices and computers using a USB cable;
ToolsAndroid ADB WIFI ADB USB to WIFI ;
- Unplug the USB cable;
At this point, you can debug your program over WiFi as you did with USB cable debugging.
End
Now, we have a holistic understanding of the technologies that Android applications need to use, and this knowledge is now able to solve the debugging problems that most applications need.
In the following, we will elaborate on the advanced usage of debugging, such as Ddms the detailed usage of various functions.
Androidstudio application Debugging techniques (bottom)