Android Studio "cannot resolve symbol" but project compiles and works

Android Studio

Android Studio Problem Overview


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.

Android Studio Solutions


Solution 1 - Android Studio

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.

Solution 2 - Android Studio

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

Solution 3 - Android Studio

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.

Solution 4 - Android Studio

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'

Solution 5 - Android Studio

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.

Solution 6 - Android Studio

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

Solution 7 - Android Studio

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

Solution 8 - Android Studio

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.

Solution 9 - Android Studio

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).

Solution 10 - Android Studio

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

Solution 11 - Android Studio

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.

Solution 12 - Android Studio

Update

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

to the last version worked for me.

Solution 13 - Android Studio

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmesiboView Question on Stackoverflow
Solution 1 - Android StudioTaoBitView Answer on Stackoverflow
Solution 2 - Android StudiomesiboView Answer on Stackoverflow
Solution 3 - Android Studiouser2702125View Answer on Stackoverflow
Solution 4 - Android StudiomuzamilView Answer on Stackoverflow
Solution 5 - Android StudioSajjad AliView Answer on Stackoverflow
Solution 6 - Android StudioFavour Felix ChinemeremView Answer on Stackoverflow
Solution 7 - Android StudiourSusView Answer on Stackoverflow
Solution 8 - Android StudioTheRealTechWizView Answer on Stackoverflow
Solution 9 - Android StudioInoyView Answer on Stackoverflow
Solution 10 - Android StudioDyvokerView Answer on Stackoverflow
Solution 11 - Android StudioAshokView Answer on Stackoverflow
Solution 12 - Android StudioRegis_AGView Answer on Stackoverflow
Solution 13 - Android StudioKakumanu siva krishnaView Answer on Stackoverflow