52

The project compiles fine. However, Android studio 3.0.1 shows reference to one particular library in red and displays "cannot resolve symbol". Even single stepping into that library module doesn't work.

I already tried various options like 1) Invalidate cache/restart 2) deleted build directory 3) clean and rebuild but nothing seems to be working.

Interestingly, when Android Studio is rebuilding indexes after invalidate/restart, it momentarily shows that library references in while but then again in red.

2
  • I've had something similar, its as if the Android Studio doesn't detect when somethings changed even though it compiles OK. The only way I've found to make it work correctly is to close down all instances of Android Studio and re-open it again. Its a huge pain in the next if your doing frequent code changes to a library.
    – Boardy
    Dec 20, 2017 at 16:10
  • I had a similar issue using my libraries (not external ones), see how I manage to fix this here: stackoverflow.com/a/50569818/373033
    – nah0y
    May 29, 2018 at 7:23

14 Answers 14

69

I tried Invalidate cache/restart or clean Project -> rebuild project. These didn't work for me.

The final solution was open Project window on the left side of IDE, under Project mode, delete .gradle and .idea folder, then sync, it works.

7
  • 15
    This worked for me when nothing else would, but I also had to invalidate caches / restart after I deleted the .gradle and .idea folders or else it wouldn't fix it.
    – user4106398
    May 13, 2018 at 0:26
  • Tried all sorts of things. This was the only thing that worked.
    – CKP78
    May 14, 2018 at 8:57
  • 13
    i deleted the .gradle folder, and did a invalidate cache/restart, not worked. Then i deleted .idea/libraries folder and did a invalidate cache/restart again and it worked. So maybe only the .idea/libraries folder is the one who needs to be deleted? Aug 2, 2018 at 2:04
  • 3
    Same issue here. Clean/Restart/etc. didn't help. Deleting the .idea/libraries folder finally did the trick!
    – mmo
    Aug 8, 2018 at 19:26
  • 1
    Worked for me ! Deleted .gradle, .idea, sync with gradle, invalidate cache, rebuild
    – Shimbawa
    Oct 19, 2019 at 16:59
16

Following has resolved this for me.

  1. remove library from gradle cache (in case of linux, it's in ~/.gradle/caches).
  2. remove library dependency from the build.gradle and sync
  3. restart (maybe invalidate cache)
  4. add library dependency to build.gradle and sync
  5. clean and rebuild
1
  • 1
    This was the only one that helped me. Thanks! Jan 1, 2019 at 22:18
6

This is happen to me when I move my project to other pc or open the project with other pc and with different SDK folder location. Solution: close project, delete folder .gradle and folder .idea inside project folder then open your project to sync gradle.

4

In my case changing the Gradle version worked.

In gradle-wrapper.properties

changing

distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip

to

distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

and in build.gradle (project level)

changing

classpath 'com.android.tools.build:gradle:3.3.0'

to

classpath 'com.android.tools.build:gradle:3.2.1'
3

Firsty try to Clean and rebuild project from Build -> Clean project & then Build -> Rebuild project.

If that doesn't work Invalidate Caches/Restart always works for me. Do it from File -> invalidate Caches/Restart

Invalidate Caches/Restart

Then click on invalidate and restart

invalidate and restart

Hopefully this helps.

2

Invalidate cache/restart didn't work for me.
Simple and working solution:
1: Remove all dependencies from App level Gradle and Sync.
2: Re-add all these dependencies and Sync.

It will work fine.

1
  • 1
    All my references to dependencies were giving me error at startup.Your solution worked for me. I'm glad I don't have to totally delete the library and re-add. I can just delete the dependency, sync, then re-add the dependencies. Nov 18, 2019 at 15:06
2

This has happened to me a couple of times, there are a few ways you can resolve this problem;

  1. Sync project files with gradle in the File toolbar
  2. Use the Invalidate/Restart option in the File toolbar to invalidate the caches.
  3. Delete the .idea folder and restart Android Studio
1

For me problem was that AS suggested I upgrade gradle version, (from 3.5 to 4.4), and then it started doing it.

Solution was to delete the 3.5 folder from .gradle in project

2
  • This worked for me, I had several different folders (4.2, 4.4, 4.6) and I removed all but the last version. Oct 3, 2018 at 16:10
  • I ran into this problem after an gradle upgrade, but deleting the previous gradle folders from .gradle did not work so I reverted back the the earlier gradle version and the problem was fixed. Jul 22, 2022 at 0:06
0

None of the answers worked for me

Fixed it by:

  1. Removing & adding all java files via Project window on the left side of Android Studio

  2. Commenting/un-commenting & syncing libraries in the gradle file in small groups.

And cleaning all caches before that (as part of other fixes here).

0
0

I've tried Invalidate Caches/Restart..., tried manually delete .idea and .build folders and it didn't work for my case. I using VCS (git) and I just commit my changes, removed the whole project, and Checkout from Version Control. It fixed this problem.

Android Studio 3.6.3

0

I Tried the following in order to resolve the issue:

  1. Invalidated Caches/Restart
  2. deleting .idea, .gredle under project and build under appenter image description here
  3. done clean project and rebuild project
  4. deleted the caches in the installed path Eg. {installed path}.AndroidStudio4.0\system\caches
  5. upgraded the studio to latest version [I have installed as suggested by windows, so its installed same path. I might have tried new path.]

Non of these tries helped to resolved this issue. Finaly I have tried these two steps:

  1. commented dataBinding.enabled true from build.gredle of your app as its obsolete and replaced with buildFeatures{dataBinding true}.

  2. Deleted the content of the log, tmp and caches folder from the installed path manually. Eg. {installed path}.AndroidStudio4.0\system\caches, {installed path}.AndroidStudio4.0\system\log, {installed path}.AndroidStudio4.0\system\log

  3. Restarted the android studio

Now all reference for the Binding and other classes were restored.

0

I ran into this problem after upgrading Android Plug In Version from 3.54 to 7.2.1 and Gradle version 5.41 to 7.3.3 . Reverting back to the earlier versions fixed the problem. Simply deleting the 5.41 folder in .gradle as suggested in another answer above did not work.

-1

Update

classpath 'com.android.tools.build:gradle:3.X.X' 

to the last version worked for me.

-1

Tried all of the above but nothing worked.

Got Solution by: 1. Updating Android studio to latest version 2. Updating the Gradle version to latest one

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.