在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"
是否有任何替代YouTubeAndroidPlayerApi.jar,因爲在我的情況下,YouTubeApiServiceUtil類沒有在運行時在YouTubeAndroidPlayerApi.jar中找到,導致應用程序崩潰。這三個類是我的代碼運行YouTubeApiServiceUtil,YouTubeInitializationResult,YouTubeStandalonePlayer –
該類絕對是在我剛剛下載的JAR中 –