Android and Windows Phone 7: Part 2 – Emulators – Android

DZone 's Guide to

Android and Windows Phone 7: Part 2 – Emulators – Android

· Mobile Zone ·
Free Resource

In my previous article I’ve described some of the aspects of the Windows Phone 7 emulator. Android SDK also comes with an emulator, although with a bunch of more customizable options. Let’s take a look at what we have.

When you extract the Android SDK somewhere on your local hard drive, you can open the tools folder and see emulator.exe (I am using a Windows machine for development, so the article describes how to use the emulator in the context of a Windows development environment).

Same as XDE for Windows Phone 7, you cannot just launch the emulator without passing an image. However, the Android emulator doesn’t work quite the same as XDE. First of all, it is based on AVD images (Android Virtual Device) that are created by the developer.

The developer can manually create multiple AVD instances, depending on the requirements set by the application. Those can be created through the SDK Setup application, located in the root SDK folder.

When you launch it, click on Virtual Devices in the left panel. You will see a list of currently available AVD images (if you just extracted the SDK, the list will be empty):

Each listed virtual device is a custom image that defines a test device. Since Android is currently at its 2.2 release, you can target new AVDs to previous version of the Android OS.

Once you specify the platform version, you are able to specify the size of the SD card that is going to be used by the device. In case you will be programming an application that will be using internal storage and use the AVD image you create, this will be the maximum size allowed for I/O interactions.

What I’ve noticed is that if you set the size of the SD card to be more than 2047 MiB, an error will be thrown that the size of the SD card should be more than 9MB:

I am not entirely sure whether it is a bug or not, but for value lower than 2048 it works fine.

You are also able to set custom screen resolution for the image. Even though you can set this value to one you want, an incorrect value set will cause the emulator to crash, therefore I’d recommend you using the default presets unless you really have to use a custom resolution.

Now you can perform detailed hardware customization. Basically, there is a set of pre-defined customization options and unless you explicitly need to enable or disable them, you can leave them with the default values on.

Here is what you are able to customize (with the assigned descriptive information):

  • Camera support – whether the device will support the camera or not
  • Max VM application heap size – the maximum heap size a Dalvik application might allocate before being by the system. Value is in megabytes.
  • Cache partition size
  • SD Card support – whether the device supports insertion/removal of virtual SD Cards.
  • Cache partition support –whether we use a / cache partition on the device
  • Keyboard support – whether the device has a QWERTY keyboard
  • Audio playback support – whether the device can play audio
  • Audio recording support – whether the device can record audio
  • DPad support – whether the device has DPad keys
  • Maximum vertical camera pixels
  • Accelerometer – whether there is an accelerometer in the device
  • GPS support – whether there is a GPS in the device
  • Device ram size – the amount of physical RAM on the device, in megabytes
  • Touch-screen support – whether there is a touch screen or not on the device
  • Battery support – whether the device can run on a battery
  • GSM modem support – whether there is a GSM modem in the device
  • Track-ball support –whether there is a trackball on the device
  • Maximum horizontal camera pixels

Once you complete the creation of a new AVD, you will see a message similar to this:

Now, you can either run the virtual machine from the list of available AVDs or directly from the console. If you decide to run it from the console, you will have to pass the name of the AVD to emulator.exe:

D:\Android\android-sdk-windows\tools\emulator.exe -avd C:\Users\Dennis\.android\avd\AndroidVirtual.avd

If you know the device name, you can simply use this command:

D:\Android\android-sdk-windows\tools\emulator.exe @<device-name>

As you see, the default path for AVD images (on a Windows 7 machine) is C:\Users\<username>\.android\avd\<image>.avd. Note that it is a folder that contains the device elements, including the SD card.

When launching the AVD, you can customize it by passing several command line parameters:

Android Emulator usage: emulator [options] [-qemu args]

    -sysdir <dir>                  search for system disk images in <dir>
    -system <file>                 read initial system image from <file>
    -datadir <dir>                 write user data into <dir>
    -kernel <file>                 use specific emulated kernel
    -ramdisk <file>                ramdisk image (default <system>/ramdisk.img)
    -image <file>                  obsolete, use -system <file> instead
    -init-data <file>              initial data image (default <system>/userdata.img)
    -initdata <file>               same as '-init-data <file>'
    -data <file>                   data image (default <datadir>/userdata-qemu.img)
    -partition-size <size>         system/data partition size in MBs
    -cache <file>                  cache partition image (default is temporary file)
    -no-cache                      disable the cache partition
    -nocache                       same as -no-cache
    -sdcard <file>                 SD card image (default <system>/sdcard.img
    -wipe-data                     reset the use data image (copy it from initdata)
    -avd <name>                    use a specific android virtual device
    -skindir <dir>                 search skins in <dir> (default <system>/skins)
    -skin <name>                   select a given skin
    -no-skin                       don't use any emulator skin
    -noskin                        same as -no-skin
    -memory <size>                 physical RAM size in MBs
    -netspeed <speed>              maximum network download/upload speeds
    -netdelay <delay>              network latency emulation
    -netfast                       disable network shaping
    -trace <name>                  enable code profiling (F9 to start)
    -show-kernel                   display kernel messages
    -shell                         enable root shell on current terminal
    -no-jni                        disable JNI checks in the Dalvik runtime
    -nojni                         same as -no-jni
    -logcat <tags>                 enable logcat output with given tags
    -no-audio                      disable audio support
    -noaudio                       same as -no-audio
    -audio <backend>               use specific audio backend
    -audio-in <backend>            use specific audio input backend
    -audio-out <backend>           use specific audio output backend
    -raw-keys                      disable Unicode keyboard reverse-mapping
    -radio <device>                redirect radio modem interface to character device
    -port <port>                   TCP port that will be used for the console
    -ports <consoleport>,<adbport> TCP ports used for the console and adb bridge
    -onion <image>                 use overlay PNG image over screen
    -onion-alpha <%age>            specify onion-skin translucency
    -onion-rotation 0|1|2|3        specify onion-skin rotation
    -scale <scale>                 scale emulator window
    -dpi-device <dpi>              specify device's resolution in dpi (default 165)
    -http-proxy <proxy>            make TCP connections through a HTTP/HTTPS proxy
    -timezone <timezone>           use this timezone instead of the host's default
    -dns-server <servers>          use this DNS server(s) in the emulated system
    -cpu-delay <cpudelay>          throttle CPU emulation
    -no-boot-anim                  disable animation for faster boot
    -no-window                     disable graphical window display
    -version                       display emulator version number
    -report-console <socket>       report console port to remote socket
    -gps <device>                  redirect NMEA GPS to character device
    -keyset <name>                 specify keyset file name
    -shell-serial <device>         specific character device for root shell
    -old-system                    support old (pre 1.4) system images
    -tcpdump <file>                capture network packets to file
    -bootchart <timeout>           enable bootcharting
    -charmap <file>                use specific key character map
    -prop <name>=<value>           set system property on boot
    -memcheck <flags>              enable memory access checking

     -qemu args...                 pass arguments to qemu
     -qemu -h                      display qemu help

     -verbose                      same as '-debug-init'
     -debug <tags>                 enable/disable debug messages
     -debug-<tag>                  enable specific debug messages
     -debug-no-<tag>               disable specific debug messages

Once you launch it, you can access the phone functionality depending on the configuration applied to the device. When it comes to development, you are able to choose the device you want to use for testing from Project Properties (Run/Debug settings):

Select an existing configuration and click Edit. Then, open the Target tab:

Here you are able to select an existing AVD and customize it (minimal options) before the launch.

That's it for now about the Android emulator. I hope that this article will be useful to some extent when you will be using the Android emulator.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}