ERROR Unable to load VM from snapshot, Android AVD

An Error Occurs Starting an AVD That Previously Worked

When coding and running an App in the Eclipse Integrated Development Environment (IDE), debugging can be performed on an Android Virtual Device (AVD). You may see ERROR Unable to load VM from snapshot, one solution is to clear Launch from snapshot in the AVD Launch Options dialog, Note changes saved to the AVD will be lost. To access the launch options start the AVD from the Android Virtual Device Manager.

Error Unable to Load VM from Snapshot Android AVDThe error can occur with an AVD that previously ran without problems. It usually occurs after updating the Android Software Development Kit (SDK), via the Android SDK Manager program. It can also occur if the AVD configuration has been changed using the Edit option in the SDK Manager. When starting the AVD, or when pressing the Run button which attempts to start an AVD, the Starting Android Emulator dialog shows, it displays this error message (where Name-of-AVD is the chosen AVD): Starting emulator for AVD ‘Name-of-AVD’ emulator: ERROR: Unable to load VM from snapshot. The snapshot has been saved for a different hardware configuration.

If the virtual hardware upon which the emulator executes has changed then the saved virtual machine (VM) snapshot is no longer compatible with it. The virtual hardware can change if the hardware image has been updated by a new release of the Android SDK (updated by the SDK Manager), or the AVD configuration has been edited.

Fixing Error Unable to Load VM From Snapshot

Android Virtual Device Manager IconA possible solution is to start the AVD fresh and not from a saved snapshot. Open the AVD Manager. Select the problem AVD from the list of existing AVDs. Select the Start button and the Launch Options dialog appears.

AVD Clear Launch from snapshotClick the Launch from snapshot check box to clear the tick before clicking the Launch button. The AVD starts from a fresh virtual machine image. Changes previously saved on the AVD are lost.

Occasionally you will still get an error launching the AVD. Delete the configured AVD and recreate it. (See Managing AVDs with AVD Manager.)

AVD Sound Playback for Android App Testing

No AVD Sound When Testing an Android App?

On creating an Android Virtual Device (AVD) audio playback is normally OK. However, if using an old saved AVD there may be no AVD sound. When this happens messages may be seen in LogCat, including one or more of the following. (It varies by the API level of the AVD.):

AudioTrack Error obtaining an audio buffer, giving up.

AudioTrack obtainBuffer timed out (is the CPU pegged?).

AudioFlinger could not create track, status: -12.

Be aware that the last error is also seen with other sound playback issues. These other issues are usually memory related: such as the audio file is to big; too much data in the file (e.g. sample rate to high or varies to much); or the limit (32) on the number of audio tracks attempting to be played has been reached.

Note: If you don’t see messages in LogCat the following solutions may still apply. But also check that the PC’s sound is not off! (Or turned down low). Even forgetting to unplug headphone may be why you have no AVD sound.

Solutions to Try When You Can’t Play AVD Sound

In earlier editions of the Android Software Development Kit (SDK) the AVDs may not have been created with audio playback enabled. Subsequent SDKs enabled audio when an AVD was created. If an AVD is started and there is no AVD sound try the following:

  • Uncheck Launch from snapshot when starting the AVD.
  • Edit the AVD config.ini file to set Audio playback support to yes.
  • Delete the AVD and recreate it.
  • Use a physical Android device.

He is a bit more detail on each solution for no AVD sound. (Please ensure that the Android SDK is up to date as well). Continue reading

Starting Emulator Failed to Allocate Memory

What to Try When The Android Emulator Reports A Memory Allocation Error

Occasionally when starting an Android Virtual Device (AVD) or running a project that starts an AVD in Eclipse an allocate memory error is reported. In the Starting Android Emulator dialog a message is seen similar to this one:

Starting emulator for AVD ‘Name of AVD’
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.

For example:

Android Failed To Allocate Memory

This article examines the reason for this error and possible solutions.

Why AVDs Need Large Amount of Memory

The latest Android devices now come with large memories, 1 GiB is now normal, and even larger memories will come in the future. When developing Apps for such devices it is natural to test them on AVDs that have the same specifications as the real world devices. When an AVD is set up using the AVD Manager program it is possible to choose existing device definitions. The Nexus 7 definition sets the RAM to 1024 MiB (1GiB). The RAM setting for the AVD is not all the RAM that the AVD uses. More RAM is required by the system to host and run the emulator code. An AVD given 1024 MiB can use up to 1.5 GiB when it is running. It makes having a high specification machine important when developing Android Apps.

Why AVD Memory Allocation Fails

The Failed to allocate memory:8 error usually occurs because the AVD is configured to have a large amount of RAM (>768 MiB) and the host Operating System (OS) appears not to be in a position to allocate that amount to the AVD (remember it needs to allocate more than specified because of the overhead in running the AVD). The OS may have plenty of memory available but it seems it is not currently in a position to allocate such a large chunk. For example the following screen shot shows the memory status on a Windows 7 64 bit machine with 8GB of memory that displayed the above error when an AVD to emulate a Nexus 7 attempted to start:

Windows resmon Example

This screenshot from the Windows Resource Monitor utility (perfmon.exe /res) shows virtually no free memory, but that is OK because there is plenty of Standby memory, 5.7 GiB. Standby is the memory cache and is available to newly starting programs (Windows will free cached memory when other programs need it). So why did the AVD fail to get a memory allocation? Continue reading