Android Virtual Devices 更改创建目录.

上一篇 / 下一篇  2010-04-08 19:01:11 / 个人分类:手机

转自:http://hewei1107.blog.163.com/blog/static/1275671372009910101747758/

AVD quickview

  • You need to create an AVD to run any app in the Android emulator
  • Each AVD is a completely independent virtual device, with its own hardware options, system image, and data storage.
  • You create AVD configurations to model different device environments in the Android emulator.

In this document

  1. Creating an AVD
    1. Listing targets
    2. Selecting a target
    3. Creating the AVD
    4. Setting hardware emulation options
    5. Default location of the AVD files
  2. Managing AVDs
    1. Moving an AVD
    2. Updating an AVD
    3. Deleting an AVD
  3. Command-line options

See Also

  1. Android Emulator

Android Virtual Devices (AVDs) are configurations of emulator options that let you better model an actual device.

Each AVD is made up of:

  • A hardware profile.  You can set options to define the hardware features of the virtual device. For example, you can define whether the device has a camera, whether it uses a physical QWERTY keyboard or a dialing pad, how much memory it has, and so on.
  • A mapping to a system image.  You can define what version of the Android platform. will run on the virtual device. You can choose a version of the standard Android platform. or the system image packaged with an SDK add-on.
  • Other options.  You can specify the emulator skin you want to use with the AVD, which lets you control the screen dimensions, appearance, and so on. You can also specify the emulated SD card to use with the AVD.
  • A dedicated storage area on your development machine, in which is stored the device's user data (installed applications, settings, and so on) and emulated SD card.

You can create as many AVDs as you need, based on the types of devices you want to model and the Android platforms and external libraries you want to run your application on.

In addition to the options in an AVD configuration, you can also specify emulator command-line options at launch or by using the emulator console to change behaviors or characteristics at run time. For a complete reference of emulator options, please see the Emulatordocumentation.

To create and manage AVDs, you use the android tool provided in the Android SDK. For more information about how to work with AVDs from inside your development environment, see Developing in Eclipse with ADT or Developing in Other IDEs, as appropriate for your environment.

Creating an AVD

The Android SDK does not include any preconfigured AVDs, so you need to create an AVD before you can run any application in the emulator (even the Hello World application).

To create an AVD, you use the android tool, a command-line utility available in the <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; "><sdk>/tools/</COde> directory. Managing AVDs is one of the two main function of the android tool (the other is creating and updating Android projects). Open a terminal window and change to the <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; "><sdk>/tools/</COde>directory, if needed

To create each AVD, you issue the command <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">android create avd</COde>, with options that specify a name for the new AVD and the system image you want to run on the emulator when the AVD is invoked. You can specify other options on the command line also, such as to create an emulated SD card for the new AVD, set the emulator skin to use, or set a custom location for the AVD's files.

Here's the command-line usage for creating an AVD:

android create avd -n <name> -t <targetID> [-<option> <value>] ...

You can use any name you want for the AVD, but since you are likely to be creating multiple AVDs, you should choose a name that lets you recognize the general characteristics offered by the AVD.

As shown in the usage above, you must use the <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">-t</COde> (or <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">--target</COde>) argument when creating a new AVD. The argument sets up a mapping between the AVD and the system image that you want to use whenever the AVD is invoked. You can specify any Android system image that is available in your local SDK — it can be the system image of a standard Android platform. version or that of any SDK add-on. Later, when applications use the AVD, they'll be running on the system that you specify in the <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">-t</COde> argument.

To specify the system image to use, you refer to its target ID — an integer — as assigned by the android tool. The target ID is not derived from the system image name, version, or API Level, or other attribute, so you need to have the android tool list the available system images and the target ID of each, as described in the next section. You should do this before you run the <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">android create avd</COde> command.

Listing targets

To generate a list of system image targets, use this command:

android list targets

The android tool scans the <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; "><sdk>/platforms</COde> and <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; "><sdk>/add-ons</COde> directories looking for valid system images and then generates the list of targets. Here's an example of the command output:

Available Android targets:id:1    Name: Android 1.1    Type: platform    API level: 2    Skins: HVGA (default), HVGA-L, HVGA-P, QVGA-L, QVGA-Pid:2    Name: Android 1.5    Type: platform    API level: 3    Skins: HVGA (default), HVGA-L, HVGA-P, QVGA-L, QVGA-Pid:3    Name: Google APIs    Type: add-on    Vendor: Google Inc.    Description: Android + Google APIs    Based on Android 1.5 (API level 3)    Libraries:    * com.google.android.maps (maps.jar)        API for Google Maps    Skins: HVGA (default), HVGA-L, QVGA-P, HVGA-P, QVGA-L

Selecting a target

Once you have generated the list of targets available, you can look at the characteristics of each system image — name, API Level, external libraries, and so on — and determine which target is appropriate for the new AVD.

Keep these points in mind when you are selecting a system image target for your AVD:

  • The API Level of the target is important, because your application will not be able to run on a system image whose API Level is less than that required by your application, as specified in the<COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">minSdkVersion</COde> attribute of the application's manifest file. For more information about the relationship between system API Level and application <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">minSdkVersion</COde>, see Specifying Minimum System API Version.
  • Creating at least one AVD that uses a target whose API Level is greater than that required by your application is strongly encouraged, because it allows you to test the forward-compatibility of your application. Forward-compatibility testing ensures that, when users who have downloaded your application receive a system update, your application will continue to function normally.
  • If your application declares a <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">uses-library</COde> element in its manifest file, the application can only run on a system image in which that external library is present. If you want your application to run on the AVD you are creating, check the application's <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">uses-library</COde> element and select a system image target that includes that library.

Creating the AVD

When you've selected the target you want to use and made a note of its ID, use the <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">android create avd</COde> command to create the AVD, supplying the target ID as the <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">-t</COde> argument. Here's an example that creates an AVD with name "my_android1.5" and target ID "2" (the standard Android 1.5 system image in the list above):

android create avd -n my_android1.5 -t 2

If the target you selected was a standard Android system image ("Type: platform"), the android tool next asks you whether you want to create a custom hardware profile.

Android 1.5 is a basic Android platform.Do you wish to create a custom hardware profile [no]

If you want to set custom hardware emulation options for the AVD, enter "yes" and set values as needed. If you want to use the default hardware emulation options for the AVD, just press the return key (the default is "no"). The android tool creates the AVD with name and system image mapping you requested, with the options you specified.

If you are creating an AVD whose target is an SDK add-on, the android tool does not allow you to set hardware emulation options. It assumes that the provider of the add-on has set emulation options appropriately for the device that the add-on is modeling, and so prevents you from resetting the options.

For a list of options you can use in the <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">android create avd</COde> command, see the table in Command-line options for AVDs, at the bottom of this page.

Setting hardware emulation options

When are creating a new AVD that uses a standard Android system image ("Type: platform"), the android tool lets you set hardware emulation options for virtual device. The table below lists the options available and the default values, as well as the names of properties that store the emulated hardware options in the AVD's configuration file (the config.ini file in the AVD's local directory).

CharacteristicDescriptionProperty
Device ram sizeThe amount of physical RAM on the device, in megabytes. Default value is "96".hw.ramSize
Touch-screen supportWhether there is a touch screen or not on the device. Default value is "yes".hw.touchScreen
Trackball supportWhether there is a trackball on the device. Default value is "yes".hw.trackBall
Keyboard supportWhether the device has a QWERTY keyboard. Default value is "yes".hw.keyboard
DPad supportWhether the device has DPad keys. Default value is "yes".hw.dPad
GSM modem supportWhether there is a GSM modem in the device. Default value is "yes".hw.gsmModem
Camera supportWhether the device has a camera. Default value is "no".hw.camera
Maximum horizontal camera pixelsDefault value is "640".hw.camera.maxHorizontalPixels
Maximum vertical camera pixelsDefault value is "480".hw.camera.maxVerticalPixels
GPS supportWhether there is a GPS in the device. Default value is "yes".hw.gps
Battery supportWhether the device can run on a battery. Default value is "yes".hw.battery
AccelerometerWhether there is an accelerometer in the device. Default value is "yes".hw.accelerometer
Audio recording supportWhether the device can record audio. Default value is "yes".hw.audioInput
Audio playback supportWhether the device can play audio. Default value is "yes".hw.audioOutput
SD Card supportWhether the device supports insertion/removal of virtual SD Cards. Default value is "yes".hw.sdCard
Cache partition supportWhether we use a /cache partition on the device. Default value is "yes".disk.cachePartition
Cache partition sizeDefault value is "66MB".disk.cachePartition.size

Default location of the AVD files

When you create an AVD, the android tool creates a dedicated directory for it on your development computer. The directory contains the AVD configuration file, the user data image and SD card image (if available), and any other files associated with the device. Note that the directory does not contain a system image — instead, the AVD configuration file contains a mapping to the system image, which it loads when the AVD is launched.

The android tool also creates a <AVD name>.ini file for the AVD at the root of the .android/avd directory on your computer. The file specifies the location of the AVD directory and always remains at the root the .android directory.

By default, the android tool creates the AVD directory inside <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">~/.android/avd/</COde> (on Linux/Mac), <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">C:\Documents and Settings\<user>\.android\</COde> on Windows XP, and<COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">C:\Users\<user>\.android\</COde> on Windows Vista. If you want to use a custom location for the AVD directory, you can do so by using the <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">-p <path></COde> option when you create the AVD:

android create avd -n my_android1.5 -t 2 -p path/to/my/avd

If the .android directory is hosted on a network drive, we recommend using the <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">-p</COde> option to place the AVD directory in another location. The AVD's .ini file remains in the .android directory on the network drive, regardless of the location of the AVD directory.

Managing AVDs

The sections below provide more information about how to manage AVDs once you've created them.

Moving an AVD

If you want to move or rename an AVD, you can do so using this command:

android move avd -n <name> [-<option> <value>] ...

The options for this command are listed in Command-line options for AVDs at the bottom of this page.

Updating an AVD

If, for any reason, the platform/add-on root folder has its name changed (maybe because the user has installed an update of the platform/add-on) then the AVD will not be able to load the system image that it is mapped to. In this case, the <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">android list targets</COde> command will produce this output:

The following Android Virtual Devices could not be loaded: Name: foo Path: <path>/.android/avd/foo.avd Error: Invalid value in image.sysdir. Run 'android update avd -n foo'

To fix this error, use the <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">android update avd</COde> command to recompute the path to the system images.

Deleting an AVD

You can use the android tool to delete an AVD. Here is the command usage:

android delete avd -n <name>

When you issue the command, the android tool looks for an AVD matching the specified name deletes the AVD's directory and files.

Command-line options for AVDs

The table below lists the command-line options you can use with the android tool.

ActionOptionDescriptionComments
<COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">list avds</COde> List all known AVDs, with name, path, target, and skin. 
<COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">create avd</COde><COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">-n <name> or 

</COde>

The name for the AVD.Required
<COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">-t <targetID></COde>Target ID of the system image to use with the new AVD.Required. To obtain a list of available targets, use <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">android list targets</COde>.
<COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">-c <path></COde> or 

<COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">-c <size>[K|M]</COde>

The path to the SD card image to use with this AVD or the size of a new SD card image to create for this AVD.Examples: <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">-c path/to/sdcard</COde> or <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">-c 1000M</COde>
<COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">-f</COde>Force creation of the AVDBy default, if the name of the AVD being created matches that of an existing AVD, the android tool will not create the new AVD or overwrite the existing AVD. If you specify the <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">-f</COde> option, however, the android tool will automatically overwrite any existing AVD that has the same name as the new AVD. The files and data of the existing AVD are deleted.
<COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">-p <path></COde>Path to the location at which to create the directory for this AVD's files. 
<COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">-s <name></COde> or 

<COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">-s <width>-<height></COde>

The skin to use for this AVD, identified by name or dimensions.The android tool scans for a matching skin by name or dimension in the <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">skins/</COde> directory of the target referenced in the <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">-t <targetID></COde> argument. Example: <COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">-s HVGA-L</COde>
<COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">delete avd</COde><COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">-n <name></COde>Delete the specified AVD.Required
<COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">move avd</COde><COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">-n <name></COde>The name of the AVD to move.Required
<COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">-p <path></COde>The path to the new location for the AVD. 
<COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">-r <new-name></COde>Rename the AVD. 
<COde style="color: rgb(0, 112, 0); font-family: monospace; line-height: 1em; ">update avds</COde>

TAG: Android AVD

 

评分:0

我来说两句

Open Toolbar