New book content serialization (3): common command line tools in Android SDK (1)

Source: Internet
Author: User
This article is original. If you need to reprint it, please indicate the author and the source. Thank you!

This article is serialized in the new book Android/OPhone development handouts. The complete handout for Android/OPhone development has been published.

Purchase: china-pub)

Android/OPhone development Handouts

Source code download

Previous: new book content serialization (2): lifecycle of Android Activity

1. start and close the ADB Service (adb start-server and adb kill-server)

According to the author's test, the adb service may be available after the simulator runs for a period of time (this service can be found in the Windows Process, which is used to serve the simulator or a real machine connected through a USB cable) an exception occurs. In this case, you need to shut down and restart the adb service again. Of course, restarting Eclipse may solve the problem. But that is troublesome. To manually disable the adb service, use the following command.

Adb kill-server

After the adb service is disabled, run the following command to start the adb service.

Adb start-server

2. query the current simulator/device instance (adb devices)

It is sometimes necessary to start multiple simulator instances, or to start the simulator while connecting the real machine through the USB data cable. In this case, you need to use the following command to query the number of online simulators or VMS.

Adb devices

After the preceding command is executed, the information shown in 1 is output.

Figure 1

The information in column 1st (emulator-5554 and HT9BYL904399) indicates the identifier of the simulator or real machine. Emulator-5554 indicates the simulator, where 5554 indicates the port number of the adb service serving the simulator instance. Each time a new simulator instance is started, the port number is different. HT9BYL904399 indicates the real machine connected through the USB data cable. If multiple simulators or real machines are online when running the Android program, a selection dialog box is displayed. If you choose to run on a real machine, ADT will directly install the program on the mobile phone. All the 2nd columns of output information are device, indicating that the current device is online. If the value of this column is offline, it indicates that the instance is not connected to adb, or the instance has no response.

3. install, uninstall, and run the program (adb install, adb uninstall, and am))

To run the Android program in Eclipse, you must have the Android source code project. How can I install and run only the apk file (the Android Application release package, which is equivalent to the exe file in Windows? The answer is the adb command. To install an ebook.apk file, run the following command.

Adb install ebook.apk

Assume that the package in ebook.apk is net. blogjava. mobile. ebook. You can run the following command to uninstall this application.

Adb uninstall net. blogjava. mobile. ebook

The concept of package will be learned in the future. Now, you only need to know that the package is the unique identifier of the Android application. If the program already exists on the simulator or on a real machine before installing the program, run the preceding command to uninstall the application and then install it. Or use the following command to re-install.

Adb install-r ebook.apk

When you uninstall an application, you can add the-k command line parameter to keep the data and buffer directory, and only uninstall the application. The command is as follows.

Adb uninstall-k net. blogjava. mobile. ebook

If there are multiple simulators or real machine instances on the machine, you need to use the-s command line parameter to specify the specific simulator or real machine. For example, the following commands install, reinstall, and uninstall the application on the simulator and the real machine respectively.

In emulator-5554Install ebook.apk on the simulator

Adb-s emulator-5554 install ebook.apk

Install ebook.apk on a real machine

Adb-s HT9BYL904399 install ebook.apk

In emulator-5554Reinstall ebook.apk on the simulator

Adb-s emulator-5554 install-r ebook.apk

Reinstall ebook.apk on a real machine

Adb-s HT9BYL904399 install-r ebook.apk

In emulator-5554Uninstall ebook.apk on the simulator(Do not retain data and buffer Directories)

Adb-s emulator-5554 uninstall net. blogjava. mobile. ebook

Uninstall ebook.apk on a real machine(Retain data and buffer Directories)

Adb-s HT9BYL904399 uninstall-k net. blogjava. mobile. ebook

If ebook.apk is successfully installed on the simulator and on the real machine, the information shown in Figure 2 and Figure 3 will be output respectively.


Figure 2


Figure 3

If you want to run an installed application on a simulator or a real machine, you can run the program directly by running the following command in addition to directly operating on the simulator or real machine.

In emulator-5554Run ebook.apk on the simulator

Adb-s emulator-5554 shell am start-n net. blogjava. mobile. ebook/net. blogjava. mobile. ebook. Main

Run ebook.apk on a real machine

Adb-s HT9BYL904399 shell am start-n net. blogjava. mobile. ebook/net. blogjava. mobile. ebook. Main

Mainis the main Activity of ebook.apk. It is equivalent to the main form of a Windows application or the home page of a Web application. Am is a shell command. The following section describes the shell commands in detail.

 

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.