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?
I had the same problem, none of the solutions listed here worked. The problem was my source files where not inside the right folder.
The directory structure MUST be :
[project]\[module]\src\main\java\[yourpackage]\[yourclass.java]
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:
Source: https://www.youtube.com/watch?v=FX_gCTpqhwM
Please check if you have a project path which has special characters like ! (exclamation mark).
In a similar problem that I experienced, this was the root cause - since many Java applications seem not to tolerate such special characters (For e.g. doing a 'gradlew clean' from the terminal would fail and throw a RunTimeException.). None of the other solutions posted online had helped me. But, once I had removed the ! from the path and did a clean build, Android Studio magically worked.
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.
it also helps to try to resync gradle and force a rebuild.
I tried everything listed here. Then I checked my androidmanifest.xml I'd had some stoopid mismatched due to folder renames & package renames.
None of these methods helped me in Android Studio 0.5.8.
My solution was to delete ~/.AndroidStudioPreview directory (in Ubuntu). Sorry, I have no idea where is it in other OS. This directory stores temporary files and Android Studio settings, so I missed all my settings. But it works!