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.)

ADT Android Bundle to Quickly Setup Android Development

Start Writing Google Apps on Windows

If you want to write Android Applications (Apps) you need the right software. Google provides free access to this software for Windows, Apple Mac and Linux PCs. An App is a computer program and like all programs it needs designing, writing, compiling, testing and debugging. This is all done in an Integrated Development Environment (IDE). There are many IDEs from which to choose. This article deals with the IDE provided by Google in the ADT Bundle for Windows. So read on for tips and information on installing and running the ADT Android bundle.

Use the ADT Android Bundle For Android Apps

Apps are written in computer language. Google’s preferred language for Android is the widely used Java. A popular IDE for writing Java programs is called Eclipse, from the Eclipse Foundation. The Eclipse IDE can be installed on to most PCs, including Windows PCs. For Android App development the Eclipse IDE requires the Android Software Development Kit (SDK) and the Android Development Tools (ADT), both from Google. All of these (Eclipse, SDK and ADT) are available in a large zip file from the Android Developers web site, the ADT Bundle for Windows.

Alternative Android App Development Environments

The ADT Android bundle is not the only option from Google. Instead of using the large zip file, install Eclipse, the Android SDK and ADT in separate steps. Good for those who need more control over the installation. (See our article Setup Android Development on Windows.)

A new option from Google is the Android Studio. Studio is currently under development so is only available under a beta release and thus subject to change. Studio does not use the Eclipse IDE, it uses the IntelliJ IDEA environment thus giving you a choice of editors. To set up Android Studio see our article Android Studio Install for Windows Based PCs.

Apps can be programmed in computer languages other than Java, using IDEs from companies other than Google. See the last section of this article for alternatives to using Java.

Install Java JDK

Java is Google’s preferred language for App development. As such the Java runtime and development kit needs installing before the ADT Android bundle. Go to the Java download page at http://www.oracle.com/technetwork/java/javase/downloads/index.html.

The Java Download Button

Select the Java download button and follow the instructions. Accept the license agreement and select the correct Windows installation EXE for your PC. (If unsure whether you are running 32-bit or 64-bit Windows use the System option in Control Panel. Under Basic Information the System type tells you if it is a 32-bit or 64-bit Operating System.) Run the Java installer to set up Java on your PC. See our article Installing Java on Windows (32-Bit or 64 Bit) if you need more help.

Download ADT Android Bundle

The Android SDK download page is at http://developer.android.com/sdk/index.html. Click on the Download the SDK ADT Bundle for Windows button. Accept the Terms and Conditions displayed by clicking the check box. Choose either 32-bit or 64-bit to match your Windows installation.

Another Download the SDK ADT Bundle for Windows button is enabled. Click the button to save the adt-bundle-windows-x86-YYYYMMDD.zip (32-bit) or adt-bundle-windows-x86_64-YYYYMMDD.zip (64-bit) file to your PC. Where YYYYMMDD is the release date for the package. E.g. adt-bundle-windows-x86-20130717.zip is the 32-bit ADT Android bundle released on July 17th 2013.

Extract Zip File Contents to Install Eclipse IDE and Android SDK and Tools

All the contents in the zip download need to be extracted. This can be done with Windows Explorer, however, on Windows XP you may get errors copying the files using Explorer. If so use an archive tool, such as 7Zip, to extract all the ADT Android bundle files.

The Android Developers website recommends extracting to a “Development” directory under your normal home location. However, that means a lot of program files are stored with your normal work. Some Android developers extract to C:\Program Files (this is a protected directory and you made be asked for permission to copy here), other developers install to a directory on the root of C: or other hard drive, such as C:\Android or C:\Development. Since the zip file contains a root directory named after itself simply copy that directory to a hard drive root. For example the contents of adt-bundle-windows-x86-20130717.zip can be extracted to C:\adt-bundle-windows-x86-20130717.

Add a Shortcut to Eclipse to the Desktop

Eclipse ShortcutTo access the App development environment quickly add a shortcut to your PC desktop. Using Windows Explorer open the eclipse directory in the extracted contents. Bring up the context menu (usually right-click) on the eclipse.exe program and select Create shortcut. Drag and drop (move) the new shortcut onto the desktop.

Run It!

The ADT Android Bundle is now installed. Run the eclipse.exe program (you can use the shortcut if you created one). First time in you will be asked to contribute usage statistics to Google. Select Yes or No and press the Finish button.

Create an Android Virtual Device (AVD) using the AVD Manager. An AVD allows testing of Apps without the need to use a physical device. Use the toolbar icon or select Android Virtual Device Manager from the Window menu. See our article Set Up an Android Virtual Device for App Testing for further information.

To test on a physical Android device install the manufacturers driver. With the driver installed use a USB cable to connect the device to your PC. You will need to enable USB debugging in the device settings.

Test your ADT Android Bundle installation by creating a simple App. See our article Your First Android Hello World Java Program. If you installed the ADT bundle to a drive other than C: you may get issues trying to run an App on an AVD. See our article Windows Symbolic Links for Android Installations on the D: Drive for a solution.

ADT Android Bundle Install Summary

Here is a summary of installing the ADT Bundle for Windows:

  • Download and install the Java JDK.
  • Download the ADT Bundle for Windows zip file.
  • Extract the contents to your PC.
  • Run it! (eclipse.exe).

Other Android App Development Options

If you struggle developing in Java, with the Google recommended IDEs for App development, there are other options. See our post Android Development Options, Tools and IDEs. It lists alternative development packages and languages.

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

Displaying a Bitmap in Android

Use an ImageView to Show a Raster Graphic

Showing a bitmap image, such as a Portable Network Graphics (PNG) or JPEG file, in an Android application (App) is easy. In this tutorial we show you how. It is assumed you are programming in Java using the Android SDK from within the Eclipse Integrated Development Environment (IDE). For PC users starting out in Android Java development see Set Up Windows for Android Development to prepare your development environment.

The ImageView class can be used and pointed at a bitmap stored under one of the drawable folders in the res project folders. Let us start by creating a very basic App project that will contain the ImageView and bitmap to display. If you do not know how to create a basic Android project in Eclipse see the article Your First Android Program. With Eclipse open select the File menu then New and Android Application Project. In the New Android App wizard the fields are set as follows:

  • Application Name – Bitmap
  • Project Name – Bitmap
  • Package Name – biz.tekeye.bitmap
  • Build SDK – Android 4.1 (API 16)
  • Minimum Required SDK – API 3: Android 1.5 (Cupcake) – or the lowest one installed
  • Create custom launcher icon – unchecked
  • Mark this project as a library – unchecked
  • Create project in Workspace – checked

Simple Android App Screen Open in EclipsePress the Next button. Create Activity should be checked and BlankActivity selected. Press the Next button again. On the New Blank Activity screen leave the fields as default and press Finish. The Bitmap project will be created and the App’s initial screen will load in the graphical designer. Continue reading

Fix VirtualBox after Installing HAXM

The Intel HAXM Software Sped Up AVDs But Broke VirtualBox

The recent Android SDKs have seen good performance improvements to the Android emulators (Android Virtual Devices, AVDs). The Intel Hardware Accelerated Execution Manager (HAXM) in particular allows for great AVD performance. On PCs with Intel processors that support hardware assisted virtualization (Intel Virtualization Technology, VT), and with the Intel Atom x86 Android System Image (currently at Android API 10, i.e. 2.3.x) the AVD performance is very good indeed. Unfortunately the first version of HAXM broke Oracle VirtualBox usage. The VirtualBox application is great for running other Operating Systems (OSs) when testing software. On a good PC you can happily run Linux and different versions of Windows side-by-side when testing software builds for different platforms.

After installing HAXM 1.0 when you next create a new virtual machine in VirtualBox the following message is seen when trying to start it:

VT-x/AMD-V hardware acceleration has been enabled, but is not operational. Certain guests (e.g. OS/2 and QNX) require this feature.

Please ensure that you have enabled VT-x/AMD-V properly in the BIOS of your host computer.

Now VirtualBox was happy prior to version 1.0 of HAXM being installed, the BIOS settings had not changed (remember on some PCs Intel VT needs to be enabled in the BIOS as it may be turned off by default). So that means HAXM was the cause, and not only on Windows machines but also on MAC OSX and Linux machines. Here is the actual dialog taken from a Microsoft Windows 7 machine running VirtualBox 4.1.18:

VirtualBox Intel HAXM ErrorEven stranger was that some other pre-existing virtual machines could still boot. Fortunately with the latest Android SDK release (Revision 20 to support Android OS 4.1, API 16, aka Jelly Bean) Intel had updated HAXM to version 1.0.1, which has sorted this issue.

The usual way of Keeping the Android SDK Updated will show the availability of the new HAXM release (you will need to scroll all the way down to the bottom of the update list). Note that you may need to run SDK Manager a couple of times before the HAXM update appears (in order to get SDK Manager itself updated) :

Use SDK Manager to Download Intel HAXM

Remember this just does an Intel HAXM installer download. After leaving SDK Manager and ensuring Eclipse is also updated (via the Eclipse Help menu and the Check for Updates option), the HAXM installer is run from the folder Android\android-sdk\extras\intel\Hardware_Accelerated_Execution_Manager usually located under the Program Files. Run IntelHaxm.exe, if it is replacing a previous version a message box is shown:

Confirm HAXM Update

Of course we want to continue, we want a working VirtualBox back. Click Yes and then click-through some usual installer and license screens.

HAXM Install Intro Screen

Once HAXM has been updated reboot the PC, this ensures the new version is running. Then you are back to being able to create new virtual machines in VirtualBox. You probably need to delete the virtual machines that were reporting the error. It appears that they remain broken so it is probably an internal configuration issue with them. You would not have got far with them anyway as they could not start-up.