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! 🙂

Why should I make my next mobile app in Xamarin? #Part5: You are using C#!

In this brief post, the 5th of the series, we will analyze why it’s relevant that Xamarin is build around C#! 🙂

Well, starting from basics, one of the main advantages of C# are the support of LINQ, which allows you to execute queries and select data from arrays and databases like SQLite. An example of LINQ:

LINQ

Moreover, in C# you can easily manage Events and Delegates:

EventsDelegates

And you can work with IntelliSense and Lambda expressions!
Also, C# natively supports JSON through the Json.NET library. Json.NET offers simple conversions to and from JSON strings and .NET objects, with SerializeObject and DeserializeObject methods.
Here is an example of creating a class with a method to get names:

ObjCClass C#Class

In C#, one line with LINQ is used to execute the whole command. Also, the C# class takes advantage of C# features and set properties easily.
Last but not least, the Async/Await constructs will allow you to set up a multithreading environment with the lowest effort possible. Below here a comparison between the Async/Await and the same code written in Objective-C!
ObjCAsync C#Async

See you on the next post! 😀
Happy coding! 🙂

Why should I make my next mobile app in Xamarin? #Part4: Xamarin VS Cordova/Titanium/etc

Good evening everybody, at last I found some time to write the fourth post of the series! In this short post we will analyse why you should choose Xamarin over Cordova, Titanium or any other javascript/web-based framework.

Until Xamarin was launched, the approach used while programming in Cordova, Titanium and other similar frameworks was similar to this:

JSApproach

Let’s now get deep into the problems this kind of programming was causing:

  • Browser fragmentation, was often causing developers issues because of deprecated components on updated browsers and unsupported components on old, not updatable, browsers.
  • The app was designed only for one platform, and often the design of an Android app has to be radically different than the design of the very same app running on Windows Phone or iOS.

This often caused unhappy users, which can’t use an app that was natively built for their phone and unhappy developers which received lots of complaints from their unhappy users. Unhappy developers means abandones apps, which will no longer receive updates. Also, the said frameworks have strong implementation limitations, and often can’t access all of the APIs on the target device.

And this is why Xamarin became important, thanks to its ability to easily cope with all these problems. The image down here describes how exactly Xamarin works:

XamarinApproach

The UI is built natively per platform, leveraging C#. The approach is having one shared app logic code base for all of the following platforms: iOS, Android, Mac, Windows phone, Windows Store, Windows. And, most importantly, Xamarin is built around C#, and if you want to know what’s so awesome about C#, you will have to wait until the fifth post of the series! 😀

See you soon!

Why should I make my next mobile app in Xamarin? #Part3: Xamarin is free for Students

Here is the long awaited third post of the series that will explain you why it’s conveniente to use Xamarin for application development, especially when you are a student. You can fine here the previous 2 posts:

https://guido1993.wordpress.com/2015/02/23/why-should-i-make-my-next-mobile-app-in-xamarin-part1-xamarin-performance/

https://guido1993.wordpress.com/2015/03/19/why-should-i-make-my-next-mobile-app-in-xamarin-part2-xamarin-forms/

On November 5th 2014, Xamarin officially announced the availability of a free Indie license for any current student. The Indie license allows you to build app an app of any size (even use Xamarin.Forms), but it was missing one thing. The biggest limitation to the Indie license was was that it didn’t allow for the use of the Visual Studio plugin, which meant being restricted to Xamarin Studio for development. The Indie license has a retail value of 300 USD per year, and Xamarin, making it available for free for students hugely boosted their userbase.

As of this week, Xamarin enhanced the Indie license for students to include the Visual Studio plugin. This is great for students, especially since a student can obtain a copy of Visual Studio for free from the DreamSpark program (http://www.dreamspark.com) or just use the free Visual Studio Community Edition. Even though the student license includes the Visual Studio plugin, this does not mean however that it is a Business license. The all the same restrictions still apply besides the plugin. This modification to the license saves users from the hefty $999 price tag.

Below here the link to rapidly compare the Business and Indie versions of Xamarin:

https://store.xamarin.com/

So if you are a student and are anxious to try Xamarin, apply for the free license today by going to https://xamarin.com/student and apply! All it takes is an email address and proof of enrollment to get started down the wonderful path of Xamarin development!

Happy coding! 😉

Why should I make my next mobile app in Xamarin? #Part2: Xamarin.Forms

“Xamarin.Forms is a cross-platform natively backed UI toolkit abstraction that allows developers to easily create user interfaces that can be shared across Android, iOS, and Windows Phone. The user interfaces are rendered using the native controls of the target platform, allowing Xamarin.Forms applications to retain the appropriate look and feel for each platform.”

This is the definition of what currently are Xamarin.Forms, found in the Xamarin website.

What platforms does the technology support?

The very last platform compatibility was announced just today, and in fact it’s still considered an Early Preview.

Xamarin.Forms has been updated constantly, almost weekly, over the last few months, and has been getting better and better over the time. Latest version currently available in nuget is 1.4.0.6341. https://www.nuget.org/packages/Xamarin.Forms/

Xamarin.Forms is a framework that allows developers to rapidly create cross platform user interfaces. It provides it’s own abstraction for the user interface that will be rendered using native controls on iOS, Android, or Windows Phone. This means that applications can share a large portion of their user interface code and still retain the native look and feel of the target platform.

Xamarin.Forms are written in C# and allow for rapid prototyping of applications that can evolve over time to complex applications. Because Xamarin.Form applications are native applications, they do not have the limitations of other toolkits such as browser sandboxing, limited APIs, or poor performance. Applications written using Xamarin.Forms are able to utilize any of the API’s or features of the underlying platform, such as (but not limited to) CoreMotion, PassKit, and StoreKit on iOS; NFC and Google Play Services on Android; and Tiles on Windows Phone. This also means it is possible to create applications that will have parts of their user interface created with Xamarin.Forms while other parts are created using the native UI toolkit.

Xamarin.Forms applications are architected in the same way as traditional cross-platform applications. The most common approach is to use Portable Libraries or Shared Projects to house the shared code, and then create platform specific applications that will consume the shared code.

There are two techniques to create user interfaces in Xamarin.Forms. The first one is to create UI views entirely with source code using the rich API provided by Xamarin.Forms. The other option available is to use Extensible Application Markup Language (XAML), a declarative markup language from Microsoft that is used to describe user interfaces. The user interface itself is defined in an XML file using the XAML syntax, while run time behaviour is defined in a separate code-behind file. To learn more about XAML, please read Microsoft’s XAML Overview documentation on What is XAML.

Why should I make my next mobile app in Xamarin? #Part1: Xamarin Performance

In this series of articles we are going to deeply analyze why it should be convenient for you (or not) developing a Mobile App using Xamarin.

One of the main doubts that is often raised by anyone I speak about Xamarin with is about the app performance.

I found an interesting in-depth review which analyses the differences between Xamarin’s Android and Java Android performance, as well as the differences between iOS native code and Xamarin’s iOS.

This is the test which involves Java (Android):

1-D89UbmzTJQ063oO7Wts_BQ

And this is the test that puts in comparison iOS native code and Xamarin’s C#:

1-yBr7maTbrt4NpTh5OjU8aA

In both case Xamarin is able to almost match the performance granted by the native platform itself, and frankly that’s quite awesome considering that Xamarin is still a young platform and has a lot of space to grow in the near future. In a few cases Xamarin even outperformed the native platform.

You can find the detailed performance comparison here: https://medium.com/@harrycheung/cross-platform-mobile-performance-testing-d0454f5cd4e9

And the github repo with the code used during the test here: https://github.com/harrycheung/Mobile-App-Performance

See you on the next post, and happy coding! 🙂