问题描述
我正在尝试使用 Android Studio IDE 在应用程序中开发 youtube 功能.这是我目前的代码:
I am trying to develop youtube functionality within an application using the Android Studio IDE. This is my code currently:
-
问题与进口有关.现在,我在正确的位置导入了 JAR 文件(我相信):
我也按照指示将它添加到 build.gradle 文件中:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.apis:google-api-services-youtube:v3-rev125-1.19.1'
}
而且我也确认它在正确的项目结构中:
我已经看过这个 stackoverflow,但没有任何帮助:YouTubePlayerSupportFragment 无法解析为类型
I have already looked at this stackoverflow, but there was no help there: YouTubePlayerSupportFragment cannot be resolved to a type
我已经清理"了应用程序,关闭并打开了 Android Studio,并重新启动了计算机,但我完全不知道为什么这不能识别导入.谁能帮助我了解我需要做什么才能让这些导入正常运行?
I have already 'cleaned' the app, closed and opened Android Studio, and rebooted the computer, but I am completely out of ideas as to why this is not recognizing the imports. Can anyone help me understand what I need to do to allow these imports to function correctly?
先谢谢你!
-Sil
推荐答案
我遇到了类似的问题.当我最终解决它时,我的 build.gradle 文件中不需要任何内容(任何一个).将 .jar 文件放在 libs 文件夹中就是我需要做的所有事情.看起来您发现了相同的结果,但我想列出整个步骤序列,以便任何阅读这篇文章的人都能澄清.
I had a similar issue. When I finally resolved it, I did NOT need anything in my build.gradle file (either one). Putting the .jar file in the libs folder was all that I need to do. Looks like you found the same result, but I wanted to list out the entire sequence of steps for clarification to anyone who reads this post.
基本上,这就是所需要的:
Essentially, this is all that is required:
- 从此处下载 .jar 文件.
- 确保有一个名为
libs
的文件夹,它是src
文件夹的同级文件夹(两者都应该是app
的子文件夹)文件夹. - 将该 .jar 文件复制到
libs
文件夹中. 确保您的 build.gradle 文件(
Module: app
一个,而不是Project:
一个)在依赖项部分包含这一行:
- Download the .jar file from here.
- Make sure that there is a folder called
libs
that is a sibling folder to yoursrc
folder (both should be children of theapp
folder. - Copy that .jar file into the
libs
folder. Make sure that your build.gradle file (the
Module: app
one, not theProject:
one) has this line in the dependencies section:
compile fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(dir: 'libs', include: ['*.jar'])
重新构建项目,它应该可以工作了.至少对我来说是这样.
Rebuild the project, and it should work. It did for me, at least.
这篇关于Android Studio Youtube 导入问题.'YouTubePlayerSupportFragment 无法解析'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!