Using the Android Emulator and Developer Tools to Build Bullet-Proof Android Applications, Part 1
- Mar 19, 2013
I have been programming Android applications for only about six months, not a long time, but long enough to know what is important and what isn't with regard to building successful Android applications. As it is now, only about 1% of the Android apps on the market actually make money. For these apps, it is often a combination of luck and robust applications that do not produce many errors.
With so many apps in the market now, many perform similar functions. For example, there are dozens and dozens of apps that read text messages out loud as they come in. If your app was early in the market, there was a chance for some success as there were many fewer apps to compete with.
Nowadays, it comes down to winning a major app contest to get noticed or picked by an Editor of the market to gain exposure. The contests were a big deal 3-4 years ago, but now you'd be hard-pressed to find one (and if you do, it isn't anything major). So not having contests as an option leaves the Editor picks for apps and word of mouth.
Sure, you can have your app promoted on blogs, but this only goes so far for so long. It takes tens of thousands of users to take notice of your app, and many of these sites simply do not have that traffic, though they claim to.
So what can you do to separate your app from all the others and get noticed, say by an Editor, high-profile blogs such as Techcrunch, or word of mouth? The only answer I have found thus far is effective testing and uniqueness of your application to produce any kind of consistent success on the market.
In this article, I share with you what I have learned about using the Android emulator for effective testing and to produce low error-prone apps, which improve ratings (and therefore success) on the market.
This article, Part 1 of a two-part series, covers performance and the emulator configuration options.
The next article, Part 2, will cover application testing, command-line options and more. By the time you're done with both parts, you should be well adept in using the emulator effectively.
Android Emulator Performance
One of the biggest complaints I often see on development help sites such as Stack-Overflow is that the emulator takes much too long to load—several minutes in fact. I found this to be true, even when I used a 2.2 GHz AMD processor. Sometimes it would not load at all and just hang with the Android logo flashing on the emulator screen.
Now I use an Intel i7 series processor, and the emulator loads nearly instantly with little or no wait time. A big difference. It could be because the i7 is a multi-core processor, more than dual-core.
I highly recommend the i7 processor for heavy-development. Furthermore, to increase performance, I use a USB drive as a ReadyBoost cache. You can learn more about ReadyBoost at http://en.wikipedia.org/wiki/ReadyBoost.
One of the key reasons why the emulator is painfully slow is because the Android OS uses the Dalvik Virtual Machine. Typically Java code, when compiled, is converted to machine bytecode and then executed by an application's virtual machine.
With the Android OS, Java is converted to bytecode and then to Dalvik code that is then executed by the Dalvik VM. The Dalvik VM has lower memory requirements than your traditional Java VM, thus optimizing memory usage. The emulator, in order to be a true emulation of an actual Android device (i.e., phone or tablet), must use the Dalvik VM.
To improve startup performance of the emulator, you can also you the Snapshot option. It is one of the launch options you can turn on when editing the details of an emulator using the Android Virtual Device Manager (AVDM).
In Eclipse, this manager can be accessed from your Windows menu. Taking a snapshot means that the emulator will launch to that saved state, thus launching much faster than usual.
You first have to start the emulator normally, and then when closing, a snapshot will be saved. The next time you start, it will use this saved state to launch the emulator.
Configuring the Emulator
To configure the emulator, you access the AVDM and either create a new emulator or edit an existing one. The following options are available for configuration with the Android SDK version supporting API 17. Each version of the SDK supporting the various APIs has a different flavor of the emulator, but the majority of the options remain the same.
Following are the options that are available for configuration:
From this this drop-menu, you can select a predefined device for testing. A device is a configuration that emulates a particular device model, such as the Nexus One. While there are several predefined devices that come with the SDK, you also have the ability to create your own simulation devices.
This can be done by clicking the Device Definitions tab from the AVDM. From this tab's panel, you can click the New Device button to create a new device. Below are the options that are available for configuration:
- Name: The name of the device, for example "Evo4G"
- Screen Size: The screen size in inches (i.e., 3.5")
- Resolution: The screen resolution, for example 960 x 640
- Cameras: Select a Front or Rear camera (or both)
- Input: Keyboard, or either No Nav, Dpad, or Trackball (No Nav is most common for phones).
- RAM: Amount of memory the device has (i.e., 768MB)
- Size: Normal, Small, Large, X-Large. The size often depends on the resolution: the higher the resolution, the larger the screen size. Normal screens are least 470x320.
- Screen Ratio: Long or Not Long. Long indicates that the device, when in portrait or landscape mode, has a significantly taller or wider aspect ratio than the baseline screen configuration. Not Long indicates the opposite; the aspect ratio is close to the baseline configuration.
- Density: The quantity of pixels within a physical area of the screen, usually referred to as DPI (dots per inch). There are different density ranges that belong to various categories, including mdpi, hdpi, ldpi, and so on. Mdpi represents a medium range, while ldpi is for low ranges, and hdpi is for high ranges.
- Buttons: Hardware or Software. The most common setting is Software; Hardware indicates that the device has an external hardware keyboard.
- Device States: Portrait or Landscape. It is common to include both of these modes. You can also specify these states for use with Keyboard if you enabled Keyboard as the input option.
The target API. Each Android device version is associated with a corresponding API. For example, Android 2.2 is associated with API 8. When specifying this target, it just means the maximum API that the device should operate for. If you specify a lower API (for example, API 8 and a 4.1 device runs your app), it will not work correctly for any new features included beyond API 8. It is a best practice to target as high as possible.
The target CPU of the device. ARM is for x86 processors (which most PCs use) or the MIPs CPU architecture, which is uncommon. MIPs is a higher-performance processor because it uses Registers to perform operations on. You could likely say it has the performance of a low-level language like Assembly.
You'll probably notice there is an option for Intel Hardware Accelerated Execution Manager (HAXM). HAXM is virtualization technology that is used to speed up the emulator. I personally use this and can tell you it does make quite a difference for emulator performance. You can view the requirements and instructions for installing HAXM at http://software.intel.com/en-us/articles/installation-instructions-for-intel-hardware-accelerated-execution-manager-microsoft.
Selecting this option is useful for devices that have an external hardware keyboard.
Display Skin with Hardware Controls. I personally always choose Display Skin with Hardware Controls because by doing this, you can use your computer keyboard to type in text for apps running on the emulator.
For example, if I want to send an SMS message using the emulator, the message can be typed using my keyboard, which is much faster than using the software keyboard of the emulator.
Also, by selecting the display skin option, you can quickly navigate the emulator using the hardware buttons like the Home or Back buttons. If you do not choose either option, you will be forced to use the emulator's software keyboard.
Some devices have a front camera, like the HTC Evo 4G, for example. If your device definition included a front camera, you will be able to enable this option; otherwise, it will be grayed-out. If you have a webcam, the camera will use the webcam to project the video onto the emulator screen.
Like the front camera, you can choose to enable a rear camera (which most Android phone devices have). By doing so, you can use your webcam to project the video onto the emulator. If using both a front and back camera, you can simulate each one by using two webcams.
Memory Size and VM Heap. Memory size is the amount of memory the device should have specified in MB. Many phones today now have at least 1 GB of memory. 1 GB is equal to 1024 MB.
The VM Heap specifies the heap size of the virtual machine in MB. The heap size should increase as the RAM specified gets larger. The heap is used to store instance variables of instantiated class objects. Garbage collection is used by the VM to free the heap space.
This option will set the amount of internal storage space the device will have. Phones today often have several gigs worth of native storage space. The need for external storage is becoming less needed.
This represents an external storage device. It is useful if you have used up your limited native device storage. Usually a large amount of images, etc., are good candidates for storing on an external storage device.
This option was already detailed in the Performance section of this article. It essentially allows your emulator to boot up faster.
This option is also performance related. It allows the emulator to use the graphics processing unit (GPU) of the host machine the emulator is running on. This results in a faster emulator. This option is only available in the most recent version of the SDK at this time.
This concludes part 1 of this article series. You should be more familiar with the core emulator options which are important for effective testing of your application using the emulator. In the next article, I will introduce testing scenarios, developer options, using the command line and more.