Android Studio suddenly cannot resolve symbols

后端 未结 28 2535
南笙
南笙 2020-11-22 04:42

Android Studio 0.4.2 was working fine and today I opened it and almost everything was red and the auto-completion had stopped working. I look at the imports and AS seems to

相关标签:
28条回答
  • 2020-11-22 05:00

    I had the same problem, none of the solutions listed here worked. The problem was my source files where not inside the right folder.

    The directory structure MUST be :

    [project]\[module]\src\main\java\[yourpackage]\[yourclass.java]

    0 讨论(0)
  • 2020-11-22 05:01

    Struggled with the same problem for a couple hours this morning. Building my project from command line seems to have done the trick for me.

    Exact steps -

    1. Cloned fresh repository (no Android studio files are in repo)
    2. Built debug project from command line ( ./gradlew clean assembleDebug )
    3. Open Android Studio, import project

    To check if it worked, look in your projects exploded-bundles folder, inspect a library and find the classes.jar. If it is expandable, then everything is going to be ok.

    edit - I found after doing a clean within Android studio, it broke again. So if you have to clean, you will need to do this process again.

    0 讨论(0)
  • 2020-11-22 05:02

    Be aware that the name of files and specially folders can result in this error. For instance, if you have a folder "Helpers" and the package for files in this folder is "com.whatever.helpers" it won't result in any compilation error but will cause the Android studio fail to load the symbols in that folder. One typical reason for that is when you name a folder with first capital letter, commit it on Git and later change the folder name to all lower case. The Git system won't recognize the change resulting in a discrepancy between the local and remote repositories that only the new repository clones will be affect by.

    0 讨论(0)
  • 2020-11-22 05:03

    You've already gone down the list of most things that would be helpful, but you could try:

    • Exit Android Studio
    • Back up your project
    • Delete all the .iml files and the .idea folder
    • Relaunch Android Studio and reimport your project

    By the way, the error messages you see in the Project Structure dialog are bogus for the most part.

    UPDATE:

    Android Studio 0.4.3 is available in the canary update channel, and should hopefully solve most of these issues. There may be some lingering problems; if you see them in 0.4.3, let us know, and try to give us a reliable set of steps to reproduce so we can ensure we've taken care of all code paths.

    0 讨论(0)
  • 2020-11-22 05:03

    I fixed this by removing the settings.gradle from my module subproject. It's a Java Gradle project with it's own settings.gradle file that somehow it screws it up.

    Thanks to this guy: https://stackoverflow.com/a/33978721/425238

    0 讨论(0)
  • 2020-11-22 05:04

    Another way is to download JDK 1.7 and change the path from Android Studio in the error message..and choose Home folder who is contained in Jdk 1.7 folder

    0 讨论(0)
提交回复
热议问题