4

I opened my project in Android Studio yesterday and got red everywhere with 'Cannot resolve symbol' as the description. It was completely random as no changes had been made to either the project or AS since the last time I opened the project. I ended up updating Android Studio to 2.0 and trying a bunch of solutions I found online but nothing works.

Like this guy, I have already tried:

  • Rebuilding the project
  • Cleaning the project
  • Syncing with Gradle Files
  • Closing the Project, closing AS and relaunching / reopening
  • File > Invalidate Caches / Restart
  • Examining Lint, didn't see anything obvious
  • Double checking all support libraries are up to date in the SDK manager
  • Examining my Build.gradle, although no changes and it's the same as usual, the way it was working all the time.

I have also tried the following steps (from the accepted answer):

  1. Exiting Android Studio
  2. Backing up ymyour project
  3. Deleting all the .iml files and the .idea folder
  4. Relaunching Android Studio and reimporting project

I also tried:

  • Removing the 'proguard' entry in build.gradle
  • Changing to "Use default gradle wrapper" in preferences

Another solution is to move 'buildTypes' in build.gradle but 'buildTypes' is already at the bottom of the Android section

Don't mark this as a duplicate if the "duplicate" is someone who fixed the same problem by doing something that didn't fix my problem.

Here are some screenshots:

enter image description here

As you can see, the color 'white' does exist:

enter image description here

R errors everywhere as well:

enter image description here

These errors are everywhere too:

enter image description here

Why are there two res directories and why is the one with the necessary resources a sub-directory of the java directory? Could this be related? Screenshot here:

enter image description here

EDIT: I created a drawable directory in the main res directory and added one of the drawables that won't get picked up by build variants. It removed the relevant 'Cannot resolve symbol' error. But when I deleted the main res and tried try to move the whole res directory in the java subdirectory to the main directory I got the following error:

enter image description here

EDIT: I managed to build without errors by deleting the outer res directory, copying the one inside the java one, pasting that into the main directory then deleting the one inside the java directory. How these got moved around like that I do not know. Probably caused by following the 'solution' of deleting and importing the project again. Whether it actually runs properly on a device I do not know as Android Studio is hanging for the last 20-30 minutes (as it does sometimes). If it does I may answer my own question with what I did to finally fix the problem.

Community
  • 1
  • 1
Questioner
  • 2,451
  • 4
  • 29
  • 50
  • Show us what went wrong like put some screencasts (At what words you get this error. ??) – Kathi Apr 20 '16 at 09:03
  • @Kathi I'll take a couple screenshots and edit my answer. – Questioner Apr 20 '16 at 09:04
  • @Kathi I edited my answer with screenshots – Questioner Apr 20 '16 at 09:14
  • Review your all XML files. – Shree Krishna Apr 20 '16 at 09:15
  • Make sure you have `color.xml` file in `res -> values` folder and it contains value with `Item Name White`. If not then add this. And the problem is solved. – Jay Rathod Apr 20 '16 at 09:18
  • @ShreeKrishna What am I supposed to look for? Nothing changed since the last time I built it without error. All of the resources each layout points to exist for example. – Questioner Apr 20 '16 at 09:18
  • @jaydroider White exists just like all the resources that are referenced but come up with red. I'll post a screenshot for proof. – Questioner Apr 20 '16 at 09:20
  • 2
    @Questioner May be something changed after upgrading IDE. But I am mostly sure this problem always raises if there is something error in XML. – Shree Krishna Apr 20 '16 at 09:22
  • 1
    Whatever @ShreeKrishna is saying is right. I suggest you to `Recheck` all your XML Resources. – Jay Rathod Apr 20 '16 at 09:25
  • @Questioner The way you defined value for `Item Name White` is wrong. Try with ` #FFFFFF `. as i said in res -> values -> color.xml file. – Jay Rathod Apr 20 '16 at 09:28
  • Recheck all your xml, and make sure your compile version 23 because your using 23.0.2 build tools, alway try to clean and rebuild the project – Kathi Apr 20 '16 at 09:29
  • @jaydroider I cropped that color out after I took the screen. It is wrapped in a tag. I will change it to the tag as you said and try again but I don't see how it built without errors for such a long time before I started getting this problem. – Questioner Apr 20 '16 at 09:34
  • Could you please paste code blocks instead of screenshots for anything that doesn't require a visual? Such as the entire colors.xml file and the text of the error logs? Thanks – OneCricketeer Apr 20 '16 at 09:41
  • @cricket_007 Kathi asked me to provide screenshots at what words I get the error so I did. – Questioner Apr 20 '16 at 09:45
  • @Kathi Yes, 23 and 23.0.2. That's already the case. – Questioner Apr 20 '16 at 09:47
  • What about your dependencies ? all are 23. Also post some code, Gradle files and your files contain errors. so that we can figure out . – Kathi Apr 20 '16 at 09:49
  • The errors seem to be at least partially related to build variants not being able to access main resources (that should be common to all variants). Why is this and how do I fix it? – Questioner Apr 20 '16 at 10:53

3 Answers3

0

The error shows you that you do not have value white in color constants.

Please check all your resource files (colors.xml, strings.xml and so on) - do you have line <color name="white">#FFFFFF</color> in one of them?

Goltsev Eugene
  • 3,325
  • 6
  • 25
  • 48
  • Nothing changed since before the error. Everything referenced everywhere exists. I posted a screenshot of the 'white' value in colors.xml. It's not the only example of this problem. – Questioner Apr 20 '16 at 09:28
0

Try creating a new project entirely, and copy and paste everything. XML files, classes, etc. That should solve your problem.

0

Eventually solved it by moving (by copying, pasting and deleting since AS wouldn't let me move it) a res directory that had been misplaced from deleting and re-importing the project to try and fix it initially. I don't know which one of the solutions worked but one of them must have. I just had to fix my project again after the re-importing 'solution' broke it. The res directory was a sub-directory of java when it should have been one level up as a sub-directory of main.

Questioner
  • 2,451
  • 4
  • 29
  • 50