Android Studio - 尽管构建正常,但“无法解析符号"语法高亮显示错误 [英] Android Studio - 'Cannot resolve symbol' syntax highlighting errors although build is ok
问题描述
几天以来我遇到了一个非常烦人的问题,在我尝试从备份中恢复以前工作的 Android Studio 项目之后,在获得一台新计算机后.
我在 android.support.v7.app
、android 等 Android 库中遇到无法解析符号" 语法高亮问题.support.v4.app
和 Google Play 服务,我已将其作为依赖项包含在内.但是,该项目构建良好,我可以在手机上毫无问题地运行该应用程序.
我已经验证了 SDK 安装下是否存在这些 jar 文件 - 例如\sdk\extras\android\m2repository\com\android\support\appcompat-v7\23.0.1".
我的问题与以下帖子中报告的问题非常相似:
- 解决方案
原因是我的项目路径中有一个 '!' 符号.显然,正如我现在了解到的,许多 Java 程序都因为这个原因而失败!:-)
我刚刚重命名了路径,现在可以正常工作了 :-)
<小时>附言
感谢@gabriele-mariotti 的
gradlew clean
建议.事实上,这帮助我找到了真正的根本原因.由于RuntimeException
,我无法从终端运行gradlew
:无法确定包装版本.在 org.gradle.wrapper.GradleWrapperMain.wrapperVersion
但这帮助我了解了 '!' 的效果路径上的符号,以及问题的根本原因.谢谢大家!
I have a really annoying problem since several days, after I tried to restore a previously working Android Studio project from a backup, after getting a new computer.
I have the "cannot resolve symbol" syntax highlighting problem with the classes from Android libraries such as
android.support.v7.app
,android.support.v4.app
, and Google Play Services, which I have included as dependencies. But, the project builds fine and I can run the App on phone with no problems.I have verified whether these jar files exist under SDK installation - for e.g. "\sdk\extras\android\m2repository\com\android\support\appcompat-v7\23.0.1".
My problem is quite similar to the ones reported in below posts:
- Android Studio says "cannot resolve symbol" but project compiles
- Android Studio cannot resolve symbol but code executes correctly
- Android Studio suddenly cannot resolve symbols
I have tried all the solutions provided in various stackoverflow discussions (i.e. Sync Gradle Project, Invalidate Cache/Restart, Clean/Rebuild, Deleting gradle generated files (.gradle, build, .idea directories etc.), downgrade to lower API and upgrade etc. But, no method is helpful.
I use Android Studio 1.3.2 and API 23. All build tools, support library etc. are up to date (tried with both v22.+ and v23.+ of the libraries).
Please do help if you have any other suggestions!
Extract from my build.gradle:
apply plugin: 'com.android.application' android { compileSdkVersion 22 buildToolsVersion '23.0.1' defaultConfig { applicationId "com.myapp.fun" minSdkVersion 22 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.android.support:support-v4:22.+' compile 'com.android.support:appcompat-v7:22.+' }
Screenshots of the problems can also be found below. I think Android Studio is not able to import the dependent libraries for syntax highlighting, although the compiler is able to include them and build successfully.
Screenshot:
解决方案The reason is because I had a '!' symbol in my project path. Apparently, as I learnt now, many Java programs fail due to this reason! :-)
I just renamed the path and it works fine now :-)
P.S.
Thank you @gabriele-mariotti for the
gradlew clean
suggestion. In fact, that helped me find the real root cause. I was not able to rungradlew
from the terminal due to aRuntimeException
:Could not determine wrapper version. at org.gradle.wrapper.GradleWrapperMain.wrapperVersion
But that helped me learn about the effect of '!' symbol on paths, and to the root cause of the problem. Thank you all!
这篇关于Android Studio - 尽管构建正常,但“无法解析符号"语法高亮显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!