Android Studio “cannot resolve symbol” but project compiles and works

后端 未结 13 2169
我在风中等你
我在风中等你 2020-12-24 10:49

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

相关标签:
13条回答
  • 2020-12-24 11:27

    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'
    
    0 讨论(0)
  • 2020-12-24 11:30

    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

    Then click on invalidate and restart

    Hopefully this helps.

    0 讨论(0)
  • 2020-12-24 11:32

    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.

    0 讨论(0)
  • 2020-12-24 11:35

    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.

    0 讨论(0)
  • 2020-12-24 11:37

    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.

    0 讨论(0)
  • 2020-12-24 11:37

    I Tried the following in order to resolve the issue:

    1. Invalidated Caches/Restart
    2. deleting .idea, .gredle under project and build under app
    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 讨论(0)
提交回复
热议问题