In the Android development process, often need to see some information printing.
Android test development (similar to Java's JUnit) is a good idea. But see Logcat is "kingly".
Why do you say that? Let's say you've seen the Android source code and you should know that there are a lot of such statements like log**.
So see Logcat will be more high-speed, direct to find the problem lies. To accelerate your development.
Of course. Android provides us with a good tool for ADB, full name Android Debug Bridge.
The following is a combination of your own experience in the project, to share with you the ADB tool.
First of all, make sure to hit ADB in the console will come out very much information, this indicates that your environment variable configuration OK, in any folder you can use the ADB command.
Assuming there is no word. You must go to the ADB folder and then use the ADB command.
The command is platform-tools below the Android installation package.
1. Query for several Android devices connected to ADB server
[Java]View Plaincopyprint?
- ADB devices
<textarea style="display: none" class="java" cols="50" rows="15" name="code">ADB devices</textarea>
2. Install APK
<path_to_apk> represents your apk file path (such as/home/. /*.APK).
[Java]View Plaincopyprint?
- ADB install <path_to_apk>
<textarea style="display: none" class="java" cols="50" rows="15" name="code">adb install <path_to_apk></textarea>
3. Copy files from device to local
<remote> indicates the path of the directory or file in the phone, <local> indicates the directory or path to the file in the phone
[Java]View Plaincopyprint?
- ADB pull <remote> <local>
<textarea style="display: none" class="java" cols="50" rows="15" name="code">adb pull <remote> <local></textarea>
4. Copy files from device to local
<remote> indicates the path of the directory or file in the phone, <local> indicates the directory or path to the file in the phone
[Java]View Plaincopyprint?
- ADB push <local> <remote>
<textarea style="display: none" class="java" cols="50" rows="15" name="code">adb push <local> <remote></textarea>
It is important to note that the replicated directory replicates the files in the directory recursively.
As the following example, copy the folder test below/home/mark/mpro/to the xx folder below/sdcard.
Assuming that you don't specify XX, the items below the test will be sdcard in a messy place.
[Java]View Plaincopyprint?
- ADB push/home/mark/mpro/test/sdcard/xx
<textarea style="display: none" class="java" cols="50" rows="15" name="code">adb push/home/mark/mpro/test/sdcard/xx</textarea>
5. View Logcat
[Java]View Plaincopyprint?
- ADB logcat
<textarea style="display: none" class="java" cols="50" rows="15" name="code">adb logcat</textarea>
With this view, the console will print out all the information.
Suppose you want to see a smaller range of logcat, such as a custom tag.
For example, the following sample:
Clientact is the tag of its own definition and is then used in the LOG.D ("tag", "*****info*****") method. To view the command for this information:
[Java]View Plaincopyprint?
- ADB logcat-s clientact:d
<textarea style="display: none" class="java" cols="50" rows="15" name="code">adb logcat-s clientact:d</textarea>
Pretend to look at a few tags at a time to the corresponding logcat. Can do this:
[Java]View Plaincopyprint?
- ADB logcat-s clientact:d Tag2:d Tag3:d
<textarea style="display: none" class="java" cols="50" rows="15" name="code">adb logcat-s clientact:d Tag2:d Tag3:d</textarea>
6. adb-d, ADB-E
Let's say you start your mobile device now. The simulator is started again, but the two parameters can help you to see the logcat of your phone.
In the example above. After the ADB plus the number-D or-e will be able to view mobile device or simulator printing logcat, but you just start a device there is no need to add a number!!
[Java]View Plaincopyprint?
- -d Direct Connect USB device
- -E Direct Connection simulator
- <textarea style="display: none" class="java" cols="50" rows="15" name="code">d Direct Connect USB device-E direct connection simulator</textarea>
7. Enter the shell
This way, you'll be able to hit your command as well as under Linux. Unfortunately, Android supports very few commands!
[Java]View Plaincopyprint?
- ADB shell
<textarea style="display: none" class="java" cols="50" rows="15" name="code">adb Shell</textarea>
A question is raised here:
If you now have two simulators on your computer, and you have access to two Android phones. How to operate the equipment at this time.
Perhaps you would say to turn off all devices that do not need to be operated.
Oh, this is really a method, but another way.
[Java]View Plaincopyprint?
- ADB devices
ADB devices
Get the name of the device, such as the following:
[Java]View Plaincopyprint?
- emulator- 5554 Device
- emulator-5556 device
Emulator-5554deviceemulator-5556device
In fact emulator-5556 is the serial of the device. Then we can use:
[Java]View Plaincopyprint?
- Adb-s Serial Number
to operate. For example:
[Java]View Plaincopyprint?
- adb-s emulator- 5556 logcat-s mark:d
Adb-s emulator-5556 logcat-s Mark:d
In addition, you can use the following command to get Serialnum
[Java]View Plaincopyprint?
- ADB [-e] or [-d] Get-serialno
ADB [-e] or [-d] Get-serialno
For other ADB commands, the Dev Guide section of the SDK documentation specifically describes ADB.
If you forget these commands when you use them, use the following:
[Java]View Plaincopyprint?
- ADB Help
<textarea style="display: none" class="java" cols="50" rows="15" name="code">adb</textarea> Help
Questions about ADB devices can be seen: adb:) ADB devices
Perhaps the blog continues to learn and explore the ADB shell-related commands.
ADB:) adb push, pull, logcat and etc