Saturday, April 2, 2011

Android Virtual Device (AVD) Emulator stopped working

I have been playing with Android Virtual Device and once I ran the "Hello World" application (read: copy-and-pasted from Android Development Guide) I thought I had conquered the world. My inflated sense of achievement didn't last long before the Android Virtual Device stopped working altogether. I had enough memory available and hard drive was not an issue but still the Virtual Device refused to start without giving much details. I even tried the best Tech Support answer and restarted the machine but it didn't work.

The Eclipse SDK did not show any specific error message or exit code, here is what the Eclipse SDK console showed:
[2011-04-02 19:16:32 - Emulator]
[2011-04-02 19:16:32 - Emulator] This application has requested the Runtime to terminate it in an unusual way.
[2011-04-02 19:16:32 - Emulator] Please contact the application's support team for more information.

The AVD was working perfectly fine earlier and I didn't remember changing anything that may have broken it. Based on the little information available online specific to this error and AVD, I stopped and restarted ADB (Android Debug Bridge) but that didn't help either.

I tried launching the Android SDK and AVD
Manager from within Eclipse (Window > Android SDK and AVD Manager) and it still didn't start the virtual device. The emulator.exe application would simply not show up in the Task Manager. Then I tried to launch the emulator through commandline and that helped resolve the issue. device2 was the name of the AVD.
>emulator -avd device2
Failed to allocate memory: 8 This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information.

Aha! That reminds me that I had changed the Device RAM from 256 to 1024MB and it had not started successfully after that change.

Solution: Edit the Device settings and change the RAM allocation to a lower number. I change it to 512MB and the emulator starts working.

I wonder why 1GB of RAM was too much for the Android Virtual Device manager to allocate when I have 3GB of physical RAM, 2GB of paging file and the Windows Task Manager was showing less than 2000MB under "Commit Charge" (i.e. more than 3000MB was available).