Google Play Services on Marshmallow

When it comes to working on Android apps, I really feel like I am starting completely from scratch … or maybe even a bit less than that. And I end up running across weird problems that end up causing me all kinds of issues. This post will talk about one of those problems and how I combined the posts of two others (who I am sure know much more than I about Android) to address my issue.

I am working on an app that uses maps. I am planning on targeting Marshmallow at a minimum. I am also using the Visual Studio Android Emulator. If you don’t already know, the Visual Studio emulator doesn’t come with the Google Play Services, which are required if you want to use maps in your app.

In a previous app, I was able to spin up an emulator, go to http://teamandroid.com/gapps, download the appropriate zip file and drag and drop to the emulator to install. This worked great for me on both KitKat and Lollipop emulators. On Marshmallow … not so much.

I started surfing … I mean researching. And in my research I came across an article from Cheesebaron which you can see here. In a nutshell, he recommends (with references) two different gapps packages to download. The only problem was that when I tried his method of downloading and drag and drop installing, my emulator just started an endless loop of optimizing packages and rebooting.

I then found another article from Rob Prouse about how to do a low level install of gapps packages from the SD card. When I tried his method, which used the gapps package from teamandroid.com, that failed as well. But at least it seemed to install without any obvious errors.

I finally deleted my emulator, started up a new one and combined the two articles. I downloaded the two packages recommended by Cheesebaron. I installed the first one in the manner recommended by Rob Prouse and after installation, was able to setup my Google account on the emulator. I then installed the second package from Cheesebaron using the same SD card installation method. After rebooting the emulator, I was able to deploy my app and run it. I am not sure if this is normal behavior, but I had to go into the app settings on the emulator and enable location for it. In the past, I seem to remember it asking me on first install, but I could be mistaken.

My new Marshmallow emulator setup is as follows:

  • Download gapps packages from Cheesebaron’s article:
  • Install the first package via the emulator SD card as per Rob Prouse
  • Create your google account in the settings/accounts
  • Install the second package via the emulator SD card as per Rob Prouse.

Hopefully this helps someone else and if not, writing it down will help me.

 

XF – Setup your App and Emulator

My computer was having some issues and I had to rebuild it. Luckily with Windows 10, this has never been a faster process. I make heavy use of Visual Studio team services, GitHub and OneDrive so backups are pretty easy too.

One thing I was struggling restoring was the capability of debugging my Android Xamarin Forms app in the Visual Studio emulator. Every time I started it up, it would immediately stop. Looking at the error messages in the debug output showed messages around the mscorlib.dll.so library.

All credit to this fix goes to Joost van Schaik and his post. As luck would have it, this is how I fixed it the first time, I just couldn’t remember it!

First thing is change your android options. Right click on your “droid” project and select “Properties”. Click on “Android Options” and make sure that “Use Fast Deployment (debug mode only)” is unchecked.

fastdeployment

Next you need to go into your emulator settings and fix up the processor settings. Click on the start menu button and type “hyper” and select “Hyper-V Manager”.

Right-click on the desired emulator and select settings:

hypervmanager

It’s a little hard to see, but under the context menu, you can see KitKat which is the emulator that I have been using. Settings should give you the following screen. Expand the processor node, click on “Compatibility” and make sure “Migrate to a physical computer with a different processor version” is checked. Note that you will only be able to do this if the emulator isn’t running.

emulator-processor-compat

And that was it. Once I made these two changes, I was able to debug in Visual Studio once again.

Hope you find this helpful and that by doing this post, I will remember the next time I need to rebuild my dev environment! For links to more information on these settings, I would suggest checking out Joost’s post on this subject.