Introducing the Google Play Services Component for Xamarin.Android
Today we’re excited to announce the Google Play Services component for developers who are using Xamarin.Android 4.8. Google Play Services is an add-on library that allows Android developers to take advantage of the most recent features from Google such as Google Maps Android API v2, Google Play In-app Billing v3, and Google Cloud Messaging.
Prior to this component, the only way to leverage Google Play Services in a Xamarin.Android application was to create your own Java Binding project and reference that from your Xamarin.Android project. The following diagram illustrates the manual steps that a developer had to perform in order to use Google Play Services in a Xamarin.Android application:
Xamarin does provide a sample on how to do this yourself, but we thought we could make the whole process easier. The licensing restrictions for the Google Play Services client library prevent us from shipping an assembly as a part of Xamarin.Android, so we decided to do the next best thing: create a component that will take care of many of the mundane details associated with creating the Java binding assembly for Google Play Services. The following image shows how the Google Play Services component has simplified the process:
You can see how this new component has significantly streamlined things, allowing you to concentrate on creating great applications in Xamarin.Android and not worry so much about how to bind the Java library.
Adding the Component to A Project
Adding this component to your project involves two steps. The first step, which you only need to do once, is to install the Google Play Services client library. You can do this by starting up the Android SDK Manager and selecting Google Play services from the Extras folder. You can start the Android SDK Manager from Xamarin Studio by selecting Tools…Open Android SDK Manager as shown in the screenshot below:
Users of Windows and Visual Studio can start the Android SDK Manager by looking for the Android SDK Manager icon the Start menu. The following screenshot shows the icon in Windows 8:
Once you start up the Android SDK Manager, scroll down the the Extras folder in the SDK Manager, select Google Play services and click on the Install packages button. The following screenshot shows the SDK Manager with Google Play services already installed:
Now you can start up Xamarin Studio or Visual Studio, and add the appropriate Google Play Services component to your application. There are two versions of this component:
- Google Play Services (Froyo) – Use this component if your project must support older versions of Android such as Android 2.2 (API level 8) or Android 2.3 (API level 10). If you are targeting these older API’s, then you must also add a reference to Mono.Android.Support.v4.
- Google Play Services – This component is meant for projects that only target Android 4.0 (API level 14) and higher.
The screenshot shows these two components as they will appear in Xamarin Studio:
Once you add the appropriate component to your project, you are all ready to incorporate these new Android API’s in your next great Xamarin.Android application.
You can download and look at the sample solution MapsAndLocationDemo_v3 for a practical example of these components.