Use ADB to install APK on the command line

Source: Internet
Author: User
Find D:\Softwave_Ghost\ technology software in your android-ide \ide\adt_android_eclipse\adt-bundle-windows-x86-20130219\sdk\ Platform-tools Directory has adb.exe CD to this directory and then you can do the ADB operation
or set environment variables
Environment variables, advanced system settings, properties--, My Computer
Or an administrator, open cmd in the path above setpath=
Try the ADB and see how he uses it.


Installing the APK in the emulator
1. Start and close the ADB service (ADB start-server and ADB kill-server)
After testing by the author, the ADB service is possible (this service can be found in the Windows process, which is used for the emulator or a real-time service connected via a USB cable), after the simulator has been running for a while. The ADB service needs to be re-closed and restarted. Of course, restarting eclipse may solve the problem. But that's more troublesome. If you want to close the ADB service manually, you can use the following command.
ADB kill-server
After you close the ADB service, use the following command to start the ADB service.
ADB start-server
2 querying an instance of the current emulator/device (ADB devices)
Sometimes you need to start multiple instances of the emulator, or you can start the emulator and connect the real machine via the USB cable. In this case, you need to use the following command to query how many emulators or real machines are currently online.
ADB devices
If you have multiple emulators or real-time machines online while running an Android program, a selection dialog box appears. If you choose to run on a real machine, ADT installs the program directly on your phone.
3. Install, uninstall and run the program (adb install, adb Uninstall, and am)
Running Android programs in Eclipse must have Android source engineering. If only the APK file (the Android app's release package, equivalent to the EXE file in Windows), how to install and run it. The answer is the ADB command. Suppose we want to install a ebook.apk file, we can use the following command.
ADB install ebook.apk
Assuming that the package in ebook.apk is Net.blogjava.mobile.ebook, you can uninstall the application using the following command.
ADB uninstall Net.blogjava.mobile.ebook
The concept of package will be gradually realized in future study. Now just know that the package is the only identifier for your Android app. If the program already exists on the emulator or the real machine before installing the program, you need to uninstall the application using the command above before installing it. or reinstall using the following command.
ADB install-r ebook.apk
When uninstalling an application, you can add the-K command-line parameter to preserve the data and buffer directories and only uninstall the application. The command is shown below.
ADB uninstall-k Net.blogjava.mobile.ebook
If you have more than one emulator or real machine instance on your machine, you need to specify a specific emulator or a real machine using the-s command line parameter. For example, the following command installs, re-installs, and uninstalls applications on the emulator and the real machine, respectively.
Installing the ebook.apk on the emulator-5554 simulator
Adb-s emulator-5554 Install ebook.apk
Installing EBOOK.APK on a real machine
Adb-s ht9byl904399 Install ebook.apk
Reinstall the EBOOK.APK on the emulator-5554 emulator
Adb-s emulator-5554 Install-r ebook.apk
Reinstall EBOOK.APK on the real machine
Adb-s ht9byl904399 Install-r ebook.apk
Uninstalling ebook.apk on the emulator-5554 emulator (no data and buffer directories are preserved)
Adb-s emulator-5554 Uninstall Net.blogjava.mobile.ebook
Uninstalling ebook.apk on a real machine (preserving data and buffering directories)
Adb-s ht9byl904399 uninstall-k Net.blogjava.mobile.ebook
If you want to run an installed application on a simulator or on a real machine, you can run the program directly, in addition to the operation directly on the emulator or on the real machine, using the following command.
Running ebook.apk on the emulator-5554 simulator
Adb-s emulator-5554 Shell am start-n net.blogjava.mobile.ebook/net.blogjava.mobile.ebook.main
Running ebook.apk on a real machine
Adb-s ht9byl904399 Shell am start-n net.blogjava.mobile.ebook/net.blogjava.mobile.ebook.main
Where main is the main activity of ebook.apk. Corresponds to the main page of a Windows application's primary form or Web application. AM is a shell command.

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.