Android YouTube API Incompatible With API 21 (Service Intent must be explicit)

UPDATE (Feb 10, 2015): This issue has been resolved, in YouTubeAndroidPlayerApi 1.2.1: Download the latest YouTube Android Player API

Read on for background on the original issue:


We recently upgraded our project to use Android 5.0, by setting targetSdkVersion 21 in build.gradle, and soon discovered that our embedded YouTube player blows up during initialization. When the YouTubePlayerView attempts to bind to the underlying YouTube service, this happens:
java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.google.android.youtube.api.service.START }
A little research led me to this bug, which was opened in September, 2014:


We were using YouTubePlayerSupportFragment, and I thought we might have more luck with YouTubePlayerFragment. I whipped up a simple test app, and discovered that I had the same problem. You get the same exception either way, presumably because YouTubePlayerFragment and YouTubePlayerSupportFragment are using the same YouTubePlayerView code. (I didn't want to make the transition from support-library fragments to native fragments anyway, because we've found that there are too many bugs with nested fragments.)

To make sure this hadn't already been fixed, I downloaded the latest YouTubeAndroidPlayerApi.jar from here: https://developers.google.com/youtube/android/player/downloads/. However, this turned out to be version 1.0.0 -- the version we were already using. No luck.

This is a pretty big bug, and it's been reported and re-reported many times. I see two possible workarounds:
  1. Roll back to targetSdkVersion 19, which means you can't use any of the new UI features of Material
  2. Abandon your native YouTube player, and use either a web-based alternative (I believe this is doable, but haven't tried it) or fire off an Intent, and let some other app take play the video (as was done here: http://stackoverflow.com/questions/574195/android-youtube-app-play-video-intent)
The last comment on that bug is pretty discouraging:
I've pointed this out on twitter to an Android dev who is one of the Lollipop advocates. Hopefully he is able to expedite it with the YouTube team but I wouldn't expect get your hopes up. That YouTube client API is still sitting at 1.0.0 and looks like it's been orphaned...
Millions of users will be affected by this, and as I understand it this is a VERY simple fix. I find it hard to believe Google is just going to let the embedded YouTube API die.

Just wanted to share my own findings, in case others are running into the same problem. If you hear news of a fix or have dreamed up some other workaround, please comment.

comments powered by Disqus