Search code examples
androidgitchromecastgoogle-cast

Android : Integrating Google Chrome Cast Library


I'm trying to build a Cast sender app and have been trying to follow the example of the reference app, particularly using the CastCompanionLibrary (CCL).

Is there an easier way of integrating the companion library without having to do all the mundane steps indicated in the official docs? They haven't published a maven/gradle distribution, and cloning the library into my repo has led to some problems, primarily because it leads to an empty directory in the Github repo, as indicated in the snapshot below: enter image description here

I tried downloading the zip file from the releases tab, added it to my project as a sub-module in Android Studio. The project is now not able to run, as it seems to mess with my run configuration (Run/Debug buttons are greyed out).

I'm a bit at a loss why a library that is meant to make cast integration easier is anything but. The documentation is buried into a PDF file too, instead of the more traditional readme.


Solution

  • Turns out we can use locally deployed AARs as a workaround in the meantime:

    1. Clone the CCL project into a directory outside of the main project
    2. Build the CCL project to generate AAR files: cd <CCL Dir>; ./gradlew build
    3. Import CCL into main project as a module. File->New->Import AAR/JAR
    4. Configure your dependencies to reflect CCL's. Apparently dependencies from an AAR library do not propagate up to the main project's build.gradle:

      compile 'com.google.android.gms:play-services-cast:8.1.0' compile project(':CastCompanionLibrary-debug') compile project(':CastCompanionLibrary-release')

    Note: you can also throw the AAR files into your 'libs' folder and add the following to build.gradle:

    repositories {
        jcenter()
        flatDir {
            dirs 'libs'
        }
    }
    compile 'com.google.android.libraries.cast.companionlibrary:CastCompanionLibrary-debug@aar'
    

    ...