To test your app when using the Google Play services SDK, you must use either:

A compatible Android device that runs Android 4.1 or
higher and includes Google Play Store.

The Android emulator with an
AVD that runs the Google
APIs platform based on Android 4.2.2 or higher.

Add Google Play Services to Your Project

To make the Google Play services APIs available to your app:

Open the build.gradle file inside your application module directory.

Note: Android Studio projects contain a top-level
build.gradle file and a build.gradle file for each module. Be sure to
edit the file for your application module. See
Building Your Project with Gradle for more information about Gradle.

Add a new build rule under dependencies for the latest version of
play-services, using one of the APIs listed below.

Ensure that your top-level build.gradle contains a
reference to the google() repo or to maven { url "https://maven.google.com" }.

Save the changes, and click Sync Project with Gradle Files in the toolbar.

Be sure you update this version number each time Google Play services is updated.

Note: ProGuard directives are included in the Play services
client libraries to preserve the required classes. The
Android Plugin for Gradle
automatically appends ProGuard configuration files in an AAR (Android ARchive) package and appends
that package to your ProGuard configuration. During project creation, Android Studio automatically
creates the ProGuard configuration files and build.gradle properties for ProGuard use.
To use ProGuard with Android Studio, you must enable the ProGuard setting in your
build.gradlebuildTypes. For more information, see the
ProGuard guide.

Ensure Devices Have the Google Play services APK

As described in the Google Play services overview, Google Play delivers service
updates for users on Android 4.1 and higher through the Google Play Store app.
However, updates might not reach all users immediately, so your app should
verify the version available before attempting to perform API transactions.

Note: Because it is hard to anticipate the state of each device, you must always check
for a compatible Google Play services APK before you access Google Play services features.

Because each app uses Google Play services differently, it's up to you decide the appropriate
place in your app to verify the Google Play services version. For example, if Google Play services
is required for your app at all times, you might want to do it when your app first launches. On the
other hand, if Google Play services is an optional part of your app, you can check the version
only once the user navigates to that portion of your app.