Setup for Developing with the Cast Application Framework (CAF) for Android


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 for building ads, collecting analytics, authenticating users, integrating maps, and much more. For more information, see Overview of Google Play Services. It is important for you to ensure that the correct Google Play services APK is installed on a user's device since updates might not reach all users immediately.

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 for more information about Gradle.

  2. Verify that google() is included in the listed repositories.
    repositories {
  3. Add a new build rule under dependencies for the latest version of play-services. For example:
    apply plugin: ''
        dependencies {
            implementation 'androidx.appcompat:appcompat:1.3.1'
            implementation 'androidx.mediarouter:mediarouter:1.2.5'
            implementation ''

    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, 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.

  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 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> element:
    <meta-data android:name=""
        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.

Create a Proguard exception

To prevent ProGuard from stripping away required classes, add the following lines in the /proguard-project.txt file:

-keep public class {
    public static final *** NULL;

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

-keep @interface
-keep class *
-keepclasseswithmembers class * { <fields>;
-keepclasseswithmembers class * { <methods>;

-keep @interface
-keepnames class *
-keepclassmembernames class * { *;

-keep @interface
-keep public class * {
  public <fields>;
  public <methods>;