ADB:) adb push, pull, logcat and etc

Source: Internet
Author: User

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?
    1. 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?
    1. 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?
    1. 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?
    1. 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?
    1. 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?

    1. 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?
    1. 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?
    1. 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?

    1. -d Direct Connect USB device
    2. -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?

    1. 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?
    1. ADB devices
ADB devices

Get the name of the device, such as the following:

[Java]View Plaincopyprint?
    1. emulator- 5554 Device
    2. emulator-5556 device
Emulator-5554deviceemulator-5556device

In fact emulator-5556 is the serial of the device. Then we can use:

[Java]View Plaincopyprint?
    1. Adb-s Serial Number

to operate. For example:

[Java]View Plaincopyprint?
    1. 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?
    1. 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?

    1. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.