How to overcome the 2 GB RAM limit on Android Visual Studio 2015 emulators

Good evening everybody!

As a devoted Xamarin dev, as soon as it got available, I installed Visual Studio 2015 Release Candidate on both my work machines, my desktop PC (with 16 GB of RAM) and my Surface Pro 3 (with “just” 4 GB of ram).

And this is where the issue raised: I tried running the new Visual Studio 2015 Android emulator, boosted by Hyper-V, on both PCs, but it relentlessly failed to launch multiple times on my Surface Pro 3, always returning this error:

Android Emulator 2048 MB error

“Visual Studio Emulator for Android: The emulator is unable to verify that the virtual machine is running: Not enough memory is available in the system to start an emulator that uses 2048 MB of startup RAM. Please close other applications and try to launch the emulator again. If closing other applications doesn’t help, please follow the instructions on this KB article: http://support.microsoft.com/kb/2911380/en-us”

And that’s what I did! I slavishly followed every single step that was suggested by that Microsoft article, and this would have theoretically led me to have a running Hyper-V Android emulator on my PC, but upon several restarts and attempts, nothing changed.

That’s where I opened the Hyper-V Manager and manually modified the settings of the Emulator “VS Emulator 5-inch KitKat (4.4) XXHDPI Phone.guido”, in order to make it need 1024 MB instead than 2048 MB. It may have worked out at first, but Visual Studio thought: “Why did he change the required RAM to 1024 MB? Hey! Let’s revert it to 2048 MB, so his poor PC won’t be capable of handling it!” (yeah, I have around 1.5 GB of free RAM, sadly, with just Visual Studio 2015 running on my SP3).

In complete despair, I started wandering in the Visual Studio installations folders on my PC, to check where the heck it was forcing the starting RAM of the emulator to be exactly 2048 MB. I encountered some files that didn’t help me at all, but at last I found the right ones, modified them and, upon trying again, my Hyper-V Android emulator was running great on my Surface Pro 3! 😀

The configuration (.cfg) files you have to modify are located here:

C:\Users\[YourUserName]\AppData\Local\Microsoft\VisualStudioEmulator\Android\Containers\Local\Devices

Just head to this URL and you will find the four little bastards:

FilesToModify

Now you will just have to open each one of them and change this line content, replacing the “2048” value with “1024”:

FROM: device.vm.ram.size=2048
TO: device.vm.ram.size=1024

While I didn’t try if the emulators were launching with lower RAM values, I suppose that it’s possible reducing the RAM size until 512 MB without incurring in major issues (and unless you are debugging a game or something as heavy). All I can say is that with 1024 MB the Hyper-V Android emulators run just as fine as they run with 2048 MB on my desktop PC.

I am leaving here a link to download a .zip file to make you able to download the four files, already patched and such: http://1drv.ms/1QjZExk

Well, this is what worked for me! 🙂 Feel free to post below here for more support, should you still have that infamous screen show up after following my guide!

Happy coding! 🙂

Installing Xamarin for Visual Studio 2015 Preview

By now you probably got the blurb of last week’s Microsoft announcements:

Microsoft Takes .NET Open Source And Cross-Platform

TechCrunch – Frederic Lardinois “Unsurprisingly, the company plans to work with the Xamarin-sponsored Mono community, which already produces a cross-platform open source .NET framework based on C#. “We will announce this and then take the next few months working with the Mono community,” Somasegar told me. “We are working very closely with the Xamarin guys on this.”

With .NET turnaround, Microsoft wants to create ‘one big family’ with open-source community

GeekWire – Todd Bishop “Miguel is still the man!” said an enthusiastic S. “Soma” Somasegar, the corporate vice president in charge of Microsoft’s Developer Division. Somasegar made the comments in an interview discussing the company’s plan to open-source .NET and make it possible to use Microsoft’s developer technologies to make software for — you guessed it — Mac, Linux, Android and iOS. Microsoft is working on the initiative with the Mono community and the startup Xamarin, which de Icaza co-founded.”

Microsoft open-sources server-side .Net, launches Visual Studio 2015 preview

InfoWorld – Simon Bisson “This doesn’t mean the work on cross-platform client-side .Net will stop. “We’re going to continue partnering deeply with Xamarin,” Somasegar says. That’s borne out by the upcoming release of Visual Studio, which will make it easier to add Xamarin tools to support iOS and Android development alongside Windows apps.”

As a testament of our close collaboration with Microsoft, we shipped same-day support for Android Native C++ projects in VS 2015, as well as deep integration with Microsoft’s Hyper-V based Android Emulator.

The experience basically is that now in VS 2015 you have two new templates for Android and iOS:

New Android App

New iOS App

Launching any of those two templates will create a project that is like an introduction to the product and links to download it (similar to what the Azure templates do when you don’t have Azure SDK installed):

Install Xamarin

Now you can just click that download button, and get the new integration for 2015!

If you happened to have a previous version of Xamarin for Visual Studio installed, please keep reading as you may not have gotten the 2015 bits installed by default (it’s something we’re fixing shortly).

Ensuring 2015 support is installed (only for previous Xamarin users)

By default, Windows Installer will just update the components you have previously installed, when applying an update. Since you previously didn’t have 2015 components installed, then by default you won’t be getting them installed right now. (we’re fixing that soon-ish).

Don’t worry, you don’t have to go download anything again, here are the easy steps to ensure you turn the bits on for 2015:

1 – Go to Add/Remove programs and search for Xamarin:

Add/Remove Xamarin

2 – Click Next on the installer window and select Change on the next screen:

Change MSI

3 – Finally, make sure you check and install locally the Visual Studio 2015 feature:

Install 2015 Feature

After the installer is done applying your changes, the old “starter” templates will be gone and you’ll be greeted with a bunch of template that you’re surely familiar with already (since this section applies to existing users only ;)).

In a future post I’ll delve a bit more on how we’re integrating with Microsoft C++ Android Native projects (hint: you can just add a project reference! ;)).

Enjoy!