本文是小编为大家收集整理的关于Android Studio Youtube导入的问题。 'YouTubePlayerSupportFragment无法解决'。的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。
问题描述
我正在尝试使用Android Studio IDE在应用程序中开发YouTube功能.这是我目前的代码:
-
问题围绕着进口.现在,我在正确的位置(我相信)导入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无法解决到类型
我已经"清洁"了该应用程序,封闭并打开了Android Studio,并重新启动了计算机,但是我完全没有想法,为什么这不识别进口.谁能帮助我了解我需要做什么以允许这些导入正确运行?
预先感谢您!
-sil
推荐答案
好吧,尽管是由于反复试验,但已将其修复.基本上,我们不得不强制gradle同步(即使左上方的同步按钮什么也没做,也没有重新启动).
这是我采取的步骤:
首先,我进入了build.gradle文件(错误的文件,该文件是针对项目的,而不是模块)
我在那里添加了一个编译语句,即使下面的评论说不要这样做,然后单击同步.
然后,一个错误窗口弹出:
我没有单击其中任何一个.我回到了build.gradle文件:
删除了我编写的代码,然后单击重试.
之后,它神奇地修复了自己.
不知道为什么它修复了它,或者为什么它首先不工作,但是如果有人遇到了相同的情况,请尝试一下,看看它是否有帮助.
-sil
其他推荐答案
我也有类似的问题.当我最终解决它时,我在build.gradle文件中不需要任何东西(任何一个).我需要做的就是将.jar文件放在Libs文件夹中.看起来您发现了相同的结果,但是我想向阅读此帖子的任何人列出澄清的整个步骤.
本质上,这就是所需的一切:
- 从在这里..
- 确保有一个称为libs的文件夹,该文件夹是您src文件夹的同级文件夹(两者都应是app文件夹的孩子.
- 将.jar文件复制到libs文件夹中.
-
确保您的build.gradle文件(Module: app一个,而不是Project:一个)在依赖项部分中具有此行:
编译Filetree(dir:'libs',包括:['*.jar'])
重建项目,它应该起作用.至少对我做了.
其他推荐答案
compile fileTree(dir: 'libs', include: ['*.jar'])
仅在Module:app implementation fileTree(dir: 'libs', include: ['*.jar'])上方仅添加它们就解决了我的问题.进口终于对我有效.
问题描述
I am trying to develop youtube functionality within an application using the Android Studio IDE. This is my code currently:
-
The issue is surrounding the imports. Now, I have the JAR file imported in the correct spot (I believe):
And I have also added it to the build.gradle file as was instructed:
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' }
AND I also, confirmed it is in the right project structure:
I have already looked at this stackoverflow, but there was no help there: YouTubePlayerSupportFragment cannot be resolved to a type
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?
Thank you in advance!
-Sil
推荐答案
Well, got it fixed, though it was due to trial and error. Basically, we had to force a gradle sync (even though the sync button in the top left did nothing, nor did rebooting).
Here are the steps I took:
First, I went into the build.gradle file (the WRONG one, the one that is for the project, not the module)
I added a compile statement there even though the comment below says not to do so, and clicked sync now.
Then, an error window popped up:
Which I did NOT click either of them. I went back into the build.gradle file:
Deleted the code I had written and then clicked try again.
After that, it magically fixed itself.
No clue why it fixed it or why it did not work in the first place, but if anyone ever comes across the same, try this and see if it helps.
-Sil
其他推荐答案
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:
- Download the .jar file from here.
- Make sure that there is a folder called libs that is a sibling folder to your src folder (both should be children of the app folder.
- Copy that .jar file into the libs folder.
Make sure that your build.gradle file (the Module: app one, not the Project: one) has this line in the dependencies section:
compile fileTree(dir: 'libs', include: ['*.jar'])
Rebuild the project, and it should work. It did for me, at least.
其他推荐答案
compile fileTree(dir: 'libs', include: ['*.jar'])
Adding just these in Module:app just above implementation fileTree(dir: 'libs', include: ['*.jar']) solves my problem. Imports finally worked fine for me.