2017-08-31 93 views
0

在Android 5.0和5.1設備中執行包含YouTube播放器的以下代碼的片段時,應用會崩潰。而在Android 6.0及更高版本的設備中,它工作正常。java.lang.NoClassDefFoundError:解析失敗:Lcom/google/android/youtube/player/YouTubeApiServiceUtil;

YouTubeInitializationResult result = 
    YouTubeApiServiceUtil.isYouTubeApiServiceAvailable(getActivity()); 
if (result != YouTubeInitializationResult.SUCCESS) { 
    result.getErrorDialog(getActivity(), 0).show(); 
} 

搖籃:

build.gradle dependencies { 
      compile fileTree(include: ['*.jar'], dir: 'libs') 
      compile files('libs/YouTubeAndroidPlayerApi.jar') androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', 
     { 
exclude group: 'com.android.support', module: 'support-annotations' 
      }) 
      compile project(':ResideMenu') 
      compile 'com.android.support:appcompat-v7:25.0.0' 
      compile 'com.android.support:support-v4:25.0.0' 
      compile 'com.android.support:design:25.0.0' 
      compile 'com.android.support:cardview-v7:25.0.0' 
      compile 'com.android.support:recyclerview-v7:25.0.0' 
      compile 'com.android.support:percent:25.0.0' 
      compile 'com.google.android.gms:play-services:10.2.1' 
      compile 'org.apache.commons:commons-io:1.3.2' 
      compile 'org.apache.commons:commons-lang3:3.4' } 

錯誤日誌:哪裏危機來臨

代碼

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/youtube/player/YouTubeApiServiceUtil;

Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.youtube.player.YouTubeApiServiceUtil"

+0

是否有任何替代YouTubeAndroidPlayerApi.jar,因爲在我的情況下,YouTubeApiServiceUtil類沒有在運行時在YouTubeAndroidPlayerApi.jar中找到,導致應用程序崩潰。這三個類是我的代碼運行YouTubeApiServiceUtil,YouTubeInitializationResult,YouTubeStandalonePlayer –

+0

該類絕對是在我剛剛下載的JAR中 –

回答

0

而不是使用jar文件,你可以嘗試添加在gradle這個依賴關係:

repositories { 
    mavenCentral() 
} 

dependencies { 
    compile 'com.google.apis:google-api-services-youtube:v3-rev183-1.22.0' 
} 
+0

實際問題是由於gradle compile'c​​om.google.android.gms:play-services:10.2.1'中的google play服務條目導致的。刪除了該條目並且現在工作正常。 –