[Video](https://www.youtube.com/watch?v=68jKxTvub7Y)

## Prerequisites

- Install the latest version of the Android SDK using the [Android SDK
  Manager](https://developer.android.com/tools/help/sdk-manager.html).
- Install the latest version of the appcompat and mediarouter [AndroidX
  Libraries](https://developer.android.com/jetpack/androidx) through the [Android SDK
  Manager](https://developer.android.com/tools/help/sdk-manager.html).
- Install the latest [Cast SDK in Google Play
  services](https://developer.android.com/google/play-services/setup.html) through the [Android SDK
  Manager](https://developer.android.com/tools/help/sdk-manager.html).

The Google Cast SDK for Android is part of the Google Play services SDK and does
not need to be downloaded separately.

**Note** : Google Play services gives you access to a [range of
APIs](https://developers.google.com/android) for building ads, collecting analytics, authenticating users,
integrating maps, and much more. For more information, see [Overview of Google Play
Services](https://developers.google.com/android/guides/overview).
It is important for you to [ensure that the correct Google Play services APK is
installed](https://developers.google.com/android/guides/setup#ensure_devices_have_the_google_play_services_apk)
on a user's device since updates might not reach all users immediately.

> [!NOTE]
> **Note:** Since the libraries contribute resources, you cannot simply satisfy the dependencies by including their JAR files; instead you need to [import them as
> library
> projects](https://developer.android.com/tools/support-library/setup.html#libs-with-res) for your IDE.

## Add Google Play Services to your project


Select your development environment below and add Google Play services to your project by
following the steps provided.

### Android Studio

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

1. 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](https://developer.android.com/sdk/installing/studio-build.html) for more information about Gradle.
2. Verify that `google()` is included in the listed `repositories`.

       repositories {
           google()
       }

3. Add a new build rule under `dependencies` for the latest version of `play-services`. For example:

   ```
   apply plugin: 'com.android.application'
       ...

       dependencies {
           implementation 'androidx.appcompat:appcompat:1.3.1'
           implementation 'androidx.mediarouter:mediarouter:1.2.5'
           implementation 'com.google.android.gms:play-services-cast-framework:23.0.0'
       }
   ```

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

   **Note:** If the number of method references in your app exceeds the
   [65K limit](https://developer.android.com/tools/building/multidex.html), your app may fail to
   compile. You may be able to mitigate this problem when compiling your app by specifying only
   the specific Google Play services APIs your app uses, instead of all of them. For information
   on how to do this, see
   [Selectively compiling APIs into your executable](https://developers.google.com/android/guides/setup.md.txt#split).
4. Save the changes and click **Sync Project with Gradle Files** in the toolbar.

### Other IDE

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

1. Copy the library project at `<android-sdk>/extras/google/google_play_services/libproject/google-play-services_lib/` to the location where you maintain your Android app projects.
2. In your app project, reference the Google Play services library project. See [Referencing a Library Project on the Command Line](https://developer.android.com/tools/projects/projects-cmdline.html#ReferencingLibraryProject) for more information on how to do this.

   **Note:** You should be referencing a copy of the library that you
   copied to your development workspace---you should not reference the library directly from the
   Android SDK directory.
3. After you've added the Google Play services library as a dependency for your app project, open your app's manifest file and add the following tag as a child of the [`<application>`](https://developer.android.com/guide/topics/manifest/application-element.html) element:

   ```
   <meta-data android:name="com.google.android.gms.version"
       android:value="@integer/google_play_services_version" />
   ```

Once you've set up your project to reference the library project, you can begin developing
features with the
[Google Play services APIs](https://developers.google.com/android/reference/com/google/android/gms/package-summary).

#### Create a Proguard exception

To prevent
[ProGuard](https://developer.android.com/tools/help/proguard.html) from stripping away
required classes, add the following lines in the
`/proguard-project.txt` file:

```
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}

-keepnames class * implements android.os.Parcelable
-keepclassmembers class * implements android.os.Parcelable {
  public static final *** CREATOR;
}

-keep @interface android.support.annotation.Keep
-keep @android.support.annotation.Keep class *
-keepclasseswithmembers class * {
  @android.support.annotation.Keep <fields>;
}
-keepclasseswithmembers class * {
  @android.support.annotation.Keep <methods>;
}

-keep @interface com.google.android.gms.common.annotation.KeepName
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
  @com.google.android.gms.common.annotation.KeepName *;
}

-keep @interface com.google.android.gms.common.util.DynamiteApi
-keep public @com.google.android.gms.common.util.DynamiteApi class * {
  public <fields>;
  public <methods>;
}

-dontwarn android.security.NetworkSecurityPolicy
```