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?
for me I changed the path of project and the problem fixed
I had a much stranger solution. In case anyone runs into this, it's worth double checking your gradle file. It turns out that as I was cloning this git and gradle was runnning, it deleted one line from my build.gradle (app) file.
Obviously the problem here was to just add it back and re-sync with gradle.
I faced similar problem but I followed following steps in my case :-
1).inside project under .idea folder open modules.xml. 2).check if there are two entries for same iml file. 3).delete one of duplicate entry and close android studio or build gradle file again.
In my case it worked. Hope it helps
I have finally figured out what causes this issue.
Actually, you should avoid pushing
.idea/libraries
folder to your repository. It creates weird stuff in Android Studio which tends to remove all downloaded libraries.If you have commit history, just recreate all missing library files and avoid them to be committed again. Otherwise, just remove whole
.idea
folder and reimport it into AS.I fixed this by removing the
settings.gradle
from my module subproject. It's a Java Gradle project with it's ownsettings.gradle
file that somehow it screws it up.Thanks to this guy: https://stackoverflow.com/a/33978721/425238
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.
My Solution When 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.
I guess that "Sync Project with Gradle Files" might work as well but I haven't tried it myself
Hope it helps