Create and use the Android emulator AVD from the cmd command line

Source: Internet
Author: User

For Android app testing, if the handheld Android device is scarce, we can create an Android simulator AVD instead of simulating an Android phone device, and this article describes how to create and use the AVD.

1. Create AVD
Each AVD simulates a set of virtual devices to run Android apps. Whether a new AVD is created under Eclipse or at the command line, an. Android folder is automatically created under the system default file path, and the configuration information about the AVD created is saved in the. Android directory, such as:
C:\Documents and Settings\administrator\.android



1) Create the AVD in the command line mode
Access the Tools subdirectory under the Android SDK directory (e.g. D:\Android\sdk\tools)
Run:
Android Create Avd-n Servyou-t 2



In the second step of creating the AvD file, the console prompts "whether to customize your own device", the default option is "No", and if you enter "Y", you can then customize your simulator performance parameters step-by-step as prompted.


Here T represents the target ID of the targets platform, we can use the Android list targets to see the optional parameters of T here.
Android 2.3.3 System platform for Target id=2


We can also see if the AVD just created already exists, and the available commands for Android list AVD view


Above, just simply create an AVD simulator, and of course we can customize the simulator's specific performance parameters:

Options:
-T--target the target ID of the new AVD (required)
-C--sdcard The path to a shared SD memory card or the capacity of a new SD memory card customized for the new AVD
-P--path The location path where the new AVD will be created
-N--name name of the new AVD (required)
-F--force Forced creation (overwrite existing AVD)
-S--skin new AVD skin


Examples are as follows:
will be built a avd,target id=6 called Gphone, SD memory card capacity 52M, path C:\AVD\, skin QVGA
Creating a new avd:android Create Avd-n gphone-t 6-c 52m-p C:\AVD\-S QVGA


2) Development tools Create AVD
In Eclipse. Select Windows > Android SDK and AVD Manager.
In the Post Android test development environment is described in the build, please check this post.




2. Create SDcard image file to simulate SDcard in real mobile device
Go to the Tools subdirectory under the Android SDK directory and run
Mksdcard-l SDcard 512M D:\Android\sdk\tools\sdcard.img
This creates a 512M SD card image file: View D, and a sdcard.img file under the Tools directory on D drive.




3. Load SDcard when running AVD under command line
Go to the Tools subdirectory under the Android SDK directory and run
EMULATOR-AVD Servyou-sdcard sdcard.img
Note: Here-sdcard is followed by the mirror path, because I am currently mirroring the current path, so the path prefix is omitted

After entering the command, you can start the Servyou simulator directly,

If you don't want to add-sdcard every time$sdcard _path, there are two ways:
Workaround One: You can copy the sdcard.img to the corresponding AVD directory under C:\Documents and settings\administrator\.android\avd\.
Workaround Two: Modify the configuration file, C:\Documents and settings\administrator\.android\avd\avd_name.avd\, open Config.ini, add the following line: sdcard.path= Your SD card path.



4. AVD Path Setting
As mentioned earlier, when you create an Android emulator with Eclipse or from the command line, the corresponding file is placed under "C:\Documents and Settings\administrator\.android". There are also 2 ways to change the path setting of the AVD:
Solution One:
Add a new environment variable with the name "Android_sdk_home" and change the value of the variable to the location where you want to place the ". ANDROID" folder (AVD information)
Solution Two:
Modify the path in the configuration file, such as my AVD name is MYAVD, open the file Myavd.ini file in the C:\Documents and SETTINGS\ADMINISTRATOR\.ANDROID\AVD directory to find
Target=android-5path
=c:\documents and SETTINGS\ADMINISTRATOR\.ANDROID\AVD\MYAVD.AVD
Modify its path.


the problem with Error:unknown virtual device name is typically caused by an AVD file path reference error.

5. View the currently running simulator/mobile device

Run ADB devices and may view the currently connected emulator and device



6. Install apk to simulator/real machine via command
Running adb install Apk_path



7. Uninstall by command simulator APK(Real machine to uninstall by command, need to have root permission)
The first is to use the command uninstall
Run adb uninstall Apk_package_name, such as the ' mobile e-tax ' package named CN.COM.SERVYOU.XJ
Then run adb uninstall CN.COM.SERVYOU.XJ


The second entry into the simulator operating system, through the LUnix command Delete (but this method will cause the APK cleanup dirty, there is residual data)

ADB shell (into the emulator's own operating system)

CD data/app (switch to APK's installation directory)

RM ***.apk (view in File Explorer with Eclipse Switch to DDMS, Data/app)




If you run RM cn.com.servyou.xj-1.apk, you can delete the ' mobile e-tax ' apk package
Now run LS again, thecn.com.servyou.xj-1.apk package name is gone



Third, can be directly removed from the simulator/real machine, no command, very simple
Enter Setting, applications, Manage applications, mobile electronic tax Bureau, Uninstall, you can directly delete the

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.