Search code examples
androidyoutubeyoutube-apiandroid-2.3-gingerbread

Android: NoClassDefFoundError with YouTubePlayerFragment on Gingerbread


I'm using the Youtube API to play Youtube videos in my Android app. It works fine on newer phones, but when I try to run on a device running Gingerbread, I get the error:

Unable to resolve superclass of Lcom/google/android/youtube/player/YouTubePlayerFragment; (21)
Link of class 'Lcom/google/android/youtube/player/YouTubePlayerFragment;' failed
VFY: unable to resolve static method 9606: Lcom/google/android/youtube/player/YouTubePlayerFragment;.newInstance ()Lcom/google/android/youtube/player/YouTubePlayerFragment;
thread exiting with uncaught exception (group=0x40015578)
FATAL EXCEPTION: main java.lang.NoClassDefFoundError: com.google.android.youtube.player.YouTubePlayerFragment

I've read many other SO questions regarding the NoClassDefFoundError, but I can't seem to resolve this issue. These are the things I've done:

  • Cleaned the project
  • Added YouTubeAdnroidPlayerApi.jar to my libs folder
  • Under "Order and Export" in the Java Build Path, I made sure YouTubePlayerApi.jar was checked.
  • The YouTubeAndroidPlayerApi.jar is listed under my libraries in my Java Build Path
  • Ensured that I have a version of the YouTube app on the device that is compatible with the YouTube API (the phone has YouTube Version 5.3.24)

Does anyone know how to solve this problem?


Solution

  • I don't believe fragments are supported pre-honeycomb (without appropriate compatibility libraries that is).

    Try using com.google.android.youtube.player.YouTubePlayerSupportFragment instead.

    See here for more information: https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubePlayerSupportFragment