Skip to content

Adding Google Play Services to Visual Studio Android Emulator

Out of the box, the Visual Studio Android Emulator (and the Genymotion emulator, and the Xamarin Android Player) does not support Google Cloud Messaging (GCM) push notifications.  The reason for this is that GCM is part of the Google Play Services.  And the Google Play Services are not included in the virtual machine (VM) images that the Visual Studio Android Emulator uses.

The typical Android device starts with a base Android stack that comes from the Android Open Source Project (AOSP).  Device OEMS (Samsung, Huawei, LG, etc) then license the Google Play Services from Google.  On top of that, the OEMs add any customizations that they do to Android.

Google does not allow Microsoft/Genymotion/Xamarin to include the Google Play Services with their builds from the AOSP.  Enough developers have put together versions of the package so that it’s a fairly easy process to install. They are commonly packaged under the name “GApps”.

Run the Visual Studio Emulator for Android from the Start Menu.  If you run it from VS, you may not be able to install firmware packages.  Then create a new VM.  For this example, we’ll create an Android 5.1 VM.  I tried this with Android 6 and it did not work with the GApps packages that I was able to obtain.

Emulation Manager

If you are using an existing VM, you’ll need to know which CPU architecture or ABI that the VM is running under.  Thanks to a tip from the nutty people at Intel, you can execute an ADB command to see what is on board.

adb shell getprop ro.product.cpu.abilist

Also see the documentation for the Build class.

SInce we created the VM, we know it’s Android 5.1.  If you were working with VM and were not sure of the version, you can check via the Android Settings app or from the command line with the adb command.

adb shell getprop ro.build.version.release

While we are checking stuff with ADB, the following command will return the SDK version

adb shell getprop ro.build.version.sdk
Results from the ADB commands
Results from the ADB commands

First up is the installation of an ARM translator. The VS Android Emulator gets its speed by running an x86 version of Android. The Google Play Services are usually packed up already compiled for ARM. The ARM translator lets ARM code run on an x86 image. This is usually packaged up in a .zip named ARM Translation v1.1.

Installing is easy, drag the .zip on to a running Android VM and follow the prompts.

The dialog that appears after drag and drop the ARM Translator package onto the Android VM

If it didn’t reboot the VM, reboot it to be safe.  Multiple web sites have a copy of this file.  I downloaded one from the Tech Bae blog.

ARM Translator installed

Since we have Android 5.1, we need a GApps package for Android 5.1.  There are a few places where you can download a package from, but not all of them may work.  I was hoping to to use the packages on the Open Gapps project.  None of their packages would install into my VMs.  They all reported an invalid folder error message.

The file sets available from TeamAndroid should install without any problems.  I downloaded one named gapps-lp-20150314.zip.  The “lp” in the file name stands for Lollypop, the code name for Android 5.

Drag the gapps package and drop it on your Android VM.  You should get a dialog like this:

Click the install button and let it do it’s thing.  After it completes, it should shutdown.  Restart it from the Emulator Manager.  After Android starts up, you may see a “Optimizing app X of Y” dialog.  When Android versions upgrade, the apps all need to tuned for the new version.  This is normal.

When that is all done, you should see  the Google Play icon in the app drawer.  Launch the app and provide your Google account information.  If you see an endless busy indicator, let it go for a minute, then close and restart Google Play.

You may see an error message about Google Play services having stopped.  That is normal and should go away once the Google Play services have been updated.

After installing GApps, some (many) Google apps and services will probably crash. Do not be alarmed, that is perfectly normal. Most of the files are out of date.

Get the Google Play app to run long enough for you to login and it will start updating.  To force Google Play to update itself, do the following (from Android Central):

  1. Launch Google Play
  2. Slide out the menu
  3. Tap on Settings
  4. Scroll to the bottom and tap Build version

If a newer version is a available, you’ll see a dialog with that information.

At that point, your Android VM will support push notifications.  You can install of Google Play apps like the Maps application.  These steps were tested with Visual Studio Android Emulator but they should work more or less in the same way with the Genymotion and Xamarin emulators.

The Open GApps page looks like it is a promising location to get GApp packages, they have a list of variants.  Basically each variant has more or less of the Google Apps.  To keep things simple, I wanted to use the stock version.  There is a naming scheme for gapps distributions.  It follows the pattern DistName-abi-version-variant-date.zip or a subset of that pattern

For this example, I had downloaded the full version of the x86 Android 6.0 GApps.  that came down with the following command line.

open_gapps-x86-6.0-stock-20160316.zip

It wouldn’t install, but that is the accepted pattern for naming GApp packages.  It (and the ARM version) error-ed out with an invalid directory message.  Hopefully this will be addressed in an update to the Visual Studio Android Emulator.

This article’s banner image comes from Arena4G.