【问题标题】:Android Studio: canot import com.google.android.youtubeAndroid Studio:无法导入 com.google.android.youtube
【发布时间】:2026-02-10 16:20:03
【问题描述】:

我得到了 jar 文件并将其粘贴到我项目的 lib 文件夹中。得到了 API 密钥,也写了编译代码,但仍然无法导入 com.google.android.youtube

dependencies {
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
testCompile 'junit:junit:4.12'
compile 'com.google.android.gms:play-services-vision:10.0.1'
compile 'com.google.android.gms:play-services-maps:10.0.1'
compile 'com.google.android.gms:play-services-location:10.0.1'
compile 'com.google.android.gms:play-services-places:10.0.1'
compile 'com.google.apis:google-api-services-youtube:v3-rev157-1.21.0'

}

【问题讨论】:

    标签: android android-studio youtube-api


    【解决方案1】:

    依赖项:编译文件('libs/YouTubeAndroidPlayerApi.jar')在您的 gradle 文件中有两次出现。还要编辑依赖项: compile 'com.google.apis:google-api-services-youtube:v3-rev157-1.21.0' 来编译 'com.google.apis:google-api-services-youtube:v3-rev181- 1.22.0'。您可以找到更多信息here。更新 gradle 文件后,再次构建您的项目。

    【讨论】:

    • 感谢您的帮助,但没有解决,同样的问题
    【解决方案2】:

    我在这里找到了关于 YouTube 的 Android Player API 的 issue。问题在于 YouTube API 应该通过 gradle 及其文档获得支持。我在本期中发现,其中一个社区创建了一个github,介绍如何通过 Gradle 将 YouTube Android Player API 添加到 Android 应用程序中。所以你可以看看这个如何使用它。

    欲了解更多信息,请查看相关SO question

    【讨论】:

    • 这部分显示错误 "compile 'com.github.tommus:youtube-android-player-api:1.2.1'"