Android Studio 突然无法解析符号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21100688/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Studio suddenly cannot resolve symbols
提问by Daniel Wilson
Android Studio 0.4.2 was working fine and today I opened it and almost everything was red and the auto-completion had stopped working. I look at the imports and AS seems to be telling me it can't find android.support.v4all of a sudden (offering me the option to remove the unused imports). (android.support.v7seems to be fine though).
Android Studio 0.4.2 运行良好,今天我打开它,几乎所有内容都是红色的,并且自动完成功能已停止工作。我查看了导入,AS 似乎告诉我它突然找不到android.support.v4(为我提供了删除未使用的导入的选项)。(android.support.v7似乎没问题)。
Things I have tried:
我尝试过的事情:
- Rebuilding the project
- Cleaning the project
- Syncing with Gradle Files
- Closing the Project, closing AS and relaunching / reopening
- File > Invalidate Caches / Restart
- Examining Lint, didn't see anything obvious
- Double checking all support libraries are up to date in the SDK manager
- Examining my Build.gradle, although no changes and it's the same as usual, the way it was working all the time.
- 重建项目
- 清理项目
- 与 Gradle 文件同步
- 关闭项目,关闭 AS 并重新启动/重新打开
- 文件 > 使缓存无效/重新启动
- 检查 Lint,没有看到任何明显的东西
- 在 SDK 管理器中仔细检查所有支持库是否是最新的
- 检查我的 Build.gradle,虽然没有任何变化,它和往常一样,但它一直在工作。
Here it is in case it's relevant:
这是相关的:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion '19.0.0'
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
}
}
dependencies {
compile 'com.android.support:support-v4:19.0.0'
compile 'com.android.support:gridlayout-v7:19.0.0'
compile 'com.android.support:appcompat-v7:19.0.0'
compile 'com.google.android.gms:play-services:4.0.30'
compile project(':libraries:facebook')
compile files('libs/core.jar')
}
When I hit "Sync with Gradle" and open "Project Settings" I get a red error telling me I have duplicate library references and to remove the unused ones..
当我点击“与 Gradle 同步”并打开“项目设置”时,我收到一个红色错误,告诉我我有重复的库引用并删除未使用的。
My project compiles and runs fine but I really need the autocomplete working!! Does anyone have any suggestions?
我的项目编译并运行良好,但我真的需要自动完成工作!!有没有人有什么建议?
回答by Victor H?ggqvist
None of the things mentioned earlier here did actually work for me. But then I found this menu entry in the file menu Invalidate Caches/Restart
which appears to have fixed the problem.
前面提到的所有事情都没有真正对我有用。但是后来我在文件菜单中找到了这个菜单项,Invalidate Caches/Restart
它似乎已经解决了这个问题。
I don't really know what happened in the background but when Android Studio started up again the status bar said Indexing...
for a minute or so which apparently did wonders.
我真的不知道后台发生了什么,但是当 Android Studio 再次启动时,状态栏会提示Indexing...
一分钟左右,这显然是个奇迹。
For reference I'm using Android Studio 0.5.4.
作为参考,我使用的是 Android Studio 0.5.4。
回答by Scott Barta
You've already gone down the list of most things that would be helpful, but you could try:
您已经列出了大多数有用的东西,但您可以尝试:
- Exit Android Studio
- Back up your project
- Delete all the .iml files and the .idea folder
- Relaunch Android Studio and reimport your project
- 退出 Android Studio
- 备份您的项目
- 删除所有 .iml 文件和 .idea 文件夹
- 重新启动 Android Studio 并重新导入您的项目
By the way, the error messages you see in the Project Structure dialog are bogus for the most part.
顺便说一下,您在“项目结构”对话框中看到的错误消息大部分都是假的。
UPDATE:
更新:
Android Studio 0.4.3 is available in the canary update channel, and should hopefully solve most of these issues. There may be some lingering problems; if you see them in 0.4.3, let us know, and try to give us a reliable set of steps to reproduce so we can ensure we've taken care of all code paths.
Android Studio 0.4.3 在 Canary 更新频道中可用,有望解决大部分问题。可能有一些挥之不去的问题;如果您在 0.4.3 中看到它们,请告诉我们,并尝试为我们提供一组可靠的重现步骤,以便我们确保处理所有代码路径。
回答by Manmohan Soni
Go through the link and it worked for me.
通过链接,它对我有用。
1.) Choose File option from menu on left top side of android studio.
1.) 从 android studio 左上角的菜单中选择 File 选项。
2.) Select the option : "Invalidate Cache/ Restart.." It will open an dialog.
2.) 选择选项:“使缓存无效/重新启动..”它将打开一个对话框。
3.) Click on the first button with option : "Invalidate and Restart"
3.) 单击带有选项的第一个按钮:“无效并重新启动”
4.) It will close the studio and restart it. Start indexing of the project.
4.) 它将关闭工作室并重新启动它。开始索引项目。
It resolved my problem:
它解决了我的问题:
File -> Invalidate Cache/ Restart -> Invalidate and Restart
File -> Invalidate Cache/ Restart -> Invalidate and Restart
回答by Mathieu de Brito
Android Studio 1.3
安卓工作室 1.3
- Open Module Settings
- Click on your moduleunder Modules menu
- In the properties tab, set the Source Compatibilityand Target Compatibilityto your java version.
- 打开模块设置
- 在“模块”菜单下单击您的模块
- 在属性选项卡中,将源兼容性和目标兼容性设置为您的 Java 版本。
I did nothing else and it worked for me.
我什么也没做,它对我有用。
回答by Helzgate
For me it was a "progaurd" build entry in my build.gradle. I removed the entire build section, then did a re-sync and problem solved.
对我来说,它是我的 build.gradle 中的“progaurd”构建条目。我删除了整个构建部分,然后重新同步并解决了问题。
回答by Aenon
I'm using Android Studio 3.1.4 and I was experiencing such issue when moving from my develop branch with a lower api target to another branch with target api Oreo. I tried the first solution which worked but it is quite tricky, while the second solution did not solve the problem.
我正在使用 Android Studio 3.1.4 并且在从具有较低 api 目标的开发分支移动到具有目标 api Oreo 的另一个分支时遇到了这样的问题。我尝试了第一个解决方案,但它很棘手,而第二个解决方案没有解决问题。
My SolutionWhen the problem popped back again I have tried to modify slightly my app gradle file enough to AS to ask me to sync files, and that did the trick. Then I deleted the change.
我的解决方案当问题再次出现时,我试图稍微修改我的应用程序 gradle 文件,足以让 AS 要求我同步文件,这确实成功了。然后我删除了更改。
I guess that "Sync Project with Gradle Files" might work as well but I haven't tried it myself
我想“与 Gradle 文件同步项目”也可能有效,但我自己没有尝试过
Hope it helps
希望能帮助到你
回答by Amir Uval
There is a far easier solution built into Android Studio, and it usually works for me without needing any brute force solution mentioned in other answers - so you should try this first:
Android Studio 中内置了一个更简单的解决方案,它通常对我有用,不需要其他答案中提到的任何蛮力解决方案 - 所以你应该先试试这个:
click on the "gradle" symbol on the right side of Android Studio, and then on the "Refresh all Gradle projects" tool.
点击Android Studio右侧的“gradle”符号,然后点击“Refresh all Gradle projects”工具。
回答by David T.
Thought i'd throw this out there too:
以为我也会把它扔出去:
the thing that worked for me was changing my build variant back to a variant that was working previously. For some reason i had changed this before (and i forgot why).
对我有用的事情是将我的构建变体改回以前可用的变体。出于某种原因,我之前已经改变了这一点(我忘记了为什么)。
either way, the best thing to do is to try to remember what you changed that day (it could be something as minor as cleaning, or going back to a previous git commit)...etc.
无论哪种方式,最好的办法是尝试记住那天你改变了什么(它可能是像清理这样的小事,或者回到以前的 git commit)......等等。
it also helps to try to resync gradle and force a rebuild.
它也有助于尝试重新同步 gradle 并强制重建。
回答by Panos
Another way is to download JDK 1.7 and change the path from Android Studio in the error message..and choose Home folder who is contained in Jdk 1.7 folder
另一种方法是下载 JDK 1.7 并在错误消息中从 Android Studio 更改路径..并选择 Jdk 1.7 文件夹中包含的主文件夹
回答by opened_eyes_media
Got the same problem today. Fixed it by changing the jdk location in the project structure from \java\jdk1.7.0_05
to \java\jdk1.7.0_25
(which I didn′t know existed until now).
今天遇到了同样的问题。通过改变项目结构的JDK位置固定它\java\jdk1.7.0_05
来\java\jdk1.7.0_25
(我不知道的到现在为止)。
I′m using Android Studio 0.8.6.
我正在使用 Android Studio 0.8.6。