Android Studio "cannot resolve symbol" but project compiles and works
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.
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.
Following has resolved this for me.
- remove library from gradle cache (in case of linux, it's in ~/.gradle/caches).
- remove library dependency from the build.gradle and sync
- restart (maybe invalidate cache)
- add library dependency to build.gradle and sync
- clean and rebuild
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.