1. Trang chủ >
  2. Công Nghệ Thông Tin >
  3. Kỹ thuật lập trình >

5  Set Up an Android Virtual Device for Apps Testing

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (9.04 MB, 688 trang )


Figure 1-6.



1.5 Set Up an Android Virtual Device for Apps Testing | 11



www.it-ebooks.info



Solution

Use the Android SDK's device emulation toolkit to configure combinations of devices

and operating systems. Testing on various combinations reduces issues related to hardware differences in devices.



Discussion

Android devices are manufactured to cover a wide market, from low cost to high specification and high value. Android has also been in the marketplace for more than a

couple of years. For these reasons there are a wide range of devices with a wide range

of hardware options and operating system versions being used. A successful Application (App) will be one that can run on such a range of devices. An App developer will

only be able to test on a very small range of physical devices. Fortunately a developer's

confidence in their App can be boosted by using an Android Virtual Device (AVD).

A complied App can be tested on a physical device or a virtual device. An AVD is an

emulation of an Android platform on a host machine, usually the development machine. AVDs simplify testing for these reasons:

• Multiple AVD configurations can be created to test an App on different versions

of Android.

• Different (emulated) hardware configurations can be used, for example GPS or no

GPS.

• An AVD is automatically launched and your compiled App is installed on to it

when the 'Run' button is pressed in Eclipse.

• You can test your App on many more combinations of Android version and hardware versions than physical devices you possess.

• Testing on AVDs greatly reduces the amount of testing required on physical devices.

• AVDs can be used alongside a physical device.

• You don't need to handicap you physical device to induce error conditions, e.g.

testing on a device with no SD card, just set up an AVD with no SD card.

• An AVD can simulate network events without the costs involved in using a physical

device, e.g. simulate phone calls or send an SMS between two AVDs.

• Simulate GPS data from an AVD from different physical locations without moving

from your desk.

• When App users report bugs you can try and mimic their hardware configurations

using AVDs.

Please note that on older development machines and when emulating larger Android

devices the performance of an AVD will be less than that of a physical device.



12 | Chapter 1: Getting Started



www.it-ebooks.info



Figure 1-7.



An AVD can be configured using the 'SDK Manager' program (opened directly from

the file system or from within Eclipse). It is also possible to create AVDs from the

command line.

To create an AVD with the 'SDK Manager' load the program. When using Eclipse select

'Window' from the menu bar and then select 'Android SDK and AVD Manager'.

The program can also be started directly from the file system. For example in Windows

open 'C:\Program Files\Android\android-sdk\SDK Manager.exe'. If started directly

from the file system 'SDK Manager' will check for SDK updates, in which case press



1.5 Set Up an Android Virtual Device for Apps Testing | 13



www.it-ebooks.info



Figure 1-8.



'Cancel' to go to the main window, titled 'Android SDK and AVD Manager'. If opened

from Eclipse the main Window will show without the check for updates to the SDK.

The left hand column of the main window will list 'Virtual Devices', 'Installed packages'

and 'Available packages'. 'Virtual Devices' should already be selected, if not select 'Virtual Devices', any existing defined AVDs will be listed in the right hand table. If the

Android SDK has just been installed no AVDs may be listed.

To create an AVD select the 'New' button. The 'Create new Android Virtual Device

(AVD)' window will load.

The following fields are used to define an AVD:

Name

Give a name to the new Android device that is to be emulated. Make the name descriptive, for example if emulating a device with a version 2.1 operating system and

medium resolution screen (HVGA) a name such as Android-v2.1-HVGA is better than

AndroidDevice.

Target

This is the version of the Android operating system than will be running on the emulated

device, as an example for a device running version 2.1 this will be set to "Android 2.1update1 - API Level 7".

SD Card

Here you specify the size of the devices emulated Secure Digital (SD) card, or select an

existing SD card image (allowing the ability to share SD card data amongst different

AVD emulations). To specify a new SD card enter the size in MiBs for the card. Re14 | Chapter 1: Getting Started



www.it-ebooks.info



Figure 1-9.

1.5 Set Up an Android Virtual Device for Apps Testing | 15



www.it-ebooks.info



Figure 1-10.



member that the bigger the number the bigger the file created on the host computer

system to mimic the SD card. Alternatively select the 'File' option and browse to an

existing SD card image (on a Windows machine the 'sdcard.img' files will be found in

the sub-folders of the 'avd' directory under the '.android' directory in the logged on

users folder).

Snapshot

Check the 'Enabled' box if you want the runtime state of the emulated device to persist

between sessions, useful if a long running series of tests are being performed and when

the AVD is closed you do not want to have to start the tests from the beginning. It also

speeds up the start up time of an AVD.

Skin

Here you select the screen size for the device, a list of common screen sizes is presented

e.g. HVGA, QVGA etc. The list will vary depending on the operating system version.

Alternatively a custom resolution can be entered.

Hardware

The table under the hardware option allows the AVD to be configured with or without

certain hardware features. To change features first add them to the table using the 'New'

button (a couple of features will be added and default automatically based on the 'Target' selected). A dialog will open to allow the selection of a hardware property.

For example select 'GPS support' then 'OK'. Select 'yes' next to 'GPS support in the table

and change it to 'no'. The AVD will not support GPS.

16 | Chapter 1: Getting Started



www.it-ebooks.info



The AVD supported properties are:

Table 1-4. AVD Supported Properties

Description

Camera support

Boolean

yes or no

This determines if the AVD supports the detection of a camera.

Max VM application heap size

integer

megabyte value

The maximum size of the heap an App might allocate before being shut down by the system.

Abstracted LCD density

integer

120/160/240/320

Approximate density (dots per inch) of the AVD screen, 120 is low density, 160 for standard or normal density, 240 is high density

and 320 is extra high density.

Cache partition size

integer megabytes

xxxMB

This sets the size of cache used by the browser.

SD Card support

Boolean

yes or no

Support for a SD card.

Cache partition support

Boolean

yes or no

This determines whether a browser uses a cache.

Keyboard support

Boolean

yes or no

This controls emulation of a physical keyboard (as opposed to an on screen one).

Audio playback support

Boolean

yes or no

Support for audio play back.

1.5 Set Up an Android Virtual Device for Apps Testing | 17



www.it-ebooks.info



Description

Keyboard lid support

Boolean

yes or no

Can the emulated keyboard be opened and closed.

Audio recording support

Boolean

yes or no

Support for recording audio.

DPad support

Boolean

yes or no

This indicates emulation of a directional pad.

Maximum vertical camera pixels

integer

pixels height

This determines the height of photos taken with the camera.

Accelerometer

Boolean

yes or no

Can a tilt and movement device be detected.

GPS support

Boolean

yes or no

Can Global Positioning System data be provided.

Device ram size

integer

megabytes

This determines size of the AVD's memory.

Touch screen support

Boolean

yes or no

This determines if the AVD supports operation via the screen.

Proximity support

Boolean

yes or no



18 | Chapter 1: Getting Started



www.it-ebooks.info



Description

Support for a proximity sensor.

Battery support

Boolean

yes or no

Support for simulated battery power.

GSM modem support

Boolean

yes or no

This determines emulation of telephony abilities.

Trackball support

Boolean

yes or no

Support for a trackball.

Maximum horizontal camera pixels

integer

pixels width

This determines the width of photos taken with the camera.



When the required fields have been defined the 'Create AVD' button is pressed to generate the AVD. The AVD will now be listed on the 'Android SDK and AVD Manager'

window.

The AVD is ready to be launched using the 'Start...' button. It is also ready to be selected

in a project configuration to test an App under development. When the 'Start...' button

is pressed the 'Launch Options' window is shown.

The options at launch are:

Scale the display to real size

On larger computer monitors you will not normally need to change the AVD scale.

The dpi of the Android screens is greater than the standard dpi on computer monitors; therefore the AVD screen will appear larger than the physical device. If necessary this can be scaled back to save screen space. Use this option to get the AVD

to display at an approximate real size on the computer monitor. The values need

to be set so that the AVD screen and keyboard is not too small to be used.

Wipe user data

When the AVD is started the user data file is reset, any user data generated from

previous runs of the AVD is lost.



1.5 Set Up an Android Virtual Device for Apps Testing | 19



www.it-ebooks.info



Figure 1-11.



20 | Chapter 1: Getting Started



www.it-ebooks.info



Figure 1-12.



Launch from snapshot

If 'Snapshot' has been 'Enabled' for an AVD then after it has been first launched

subsequent launches are quicker. The AVD is loaded from a snapshot and the

Android operating system does not need to start up again. Although when the AVD

is closed the shutdown is longer because the snapshot has to be written to disk.

Save to snapshot

When the AVD is closed the current state is saved for quicker launching next time;

although close down is slower as the snapshot is written to disk. Once you have a

snapshot you can uncheck this option so closing an AVD is quick as well, though

any changes since the last snapshot will be lost.

Use the 'Launch' button to start the AVD. Once loaded it can be used like any other

Android device and driven from the keyboard and mouse of the host computer.

Error Message on Windows when Launching

When trying to launch an AVD on a Windows installation an error with the description beginning invalid command-line parameter may occur.

To fix this problem change the path to the Android SDK directory so that it does

not contain any spaces. The default installation path for the SDK is in C:\Program

Files\Android. The space in Program Files needs to be removed. To do this and

maintain a valid directory name Program Files needs to be converted to its Microsoft DOS format (also referred to as 8.3 format). This is usually the first six letters

in upper case followed by a tilde and the number 1, i.e. PROGRA~1. If other directories start with Program followed by a space then the number may need to be

increased. To see the DOS format for the Program Files directory on your machine

open a Command Prompt (via Start->All Programs->Accessories). Change to root



1.5 Set Up an Android Virtual Device for Apps Testing | 21



www.it-ebooks.info



Xem Thêm
Tải bản đầy đủ (.pdf) (688 trang)

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×