Android Studio “cannot resolve symbol” but project

2020-02-17 08:37发布

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.

10条回答
霸刀☆藐视天下
2楼-- · 2020-02-17 09:01

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.

查看更多
三岁会撩人
3楼-- · 2020-02-17 09:03

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

查看更多
对你真心纯属浪费
4楼-- · 2020-02-17 09:07

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.

查看更多
走好不送
5楼-- · 2020-02-17 09:08

Update

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

to the last version worked for me.

查看更多
叛逆
6楼-- · 2020-02-17 09:12

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

查看更多
冷血范
7楼-- · 2020-02-17 09:18

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

查看更多
登录 后发表回答