Android Studio suddenly cannot resolve symbols
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.v4 all of a sudden (offering me the option to remove the unused imports). (android.support.v7 seems to be fine though).
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.
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..
My project compiles and runs fine but I really need the autocomplete working!! Does anyone have any suggestions?
Solution 1:
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.
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.
For reference I'm using Android Studio 0.5.4.
Solution 2:
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
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.
Solution 3:
Go through the link and it worked for me.
1.) Choose File option from menu on left top side of android studio.
2.) Select the option : "Invalidate Cache/ Restart.." It will open an dialog.
3.) Click on the first button with option : "Invalidate and Restart"
4.) It will close the studio and restart it. Start indexing of the project.
It resolved my problem:
File -> Invalidate Cache/ Restart -> Invalidate and Restart
Source: https://www.youtube.com/watch?v=FX_gCTpqhwM
Solution 4:
Android Studio 1.3
- Open Module Settings
- Click on your module under Modules menu
- In the properties tab, set the Source Compatibility and Target Compatibility to your java version.
I did nothing else and it worked for me.
Solution 5:
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.