android studio cannot resolve symbol R
<p>I've been working on an app and all was going well, everything was working fine. Then I modified some code in my main activity, and when I tried to run the app, there was an apparent error in my code and the build failed.</p>

<p>After this, all the references to my layout files were no longer working (i.e., R.layout.) R was red and hover over says "Cannot resolve symbol R".</p>

<p>Searching you will find dozens of posts that propose many fixes, like: Clean Project; Rebuild Project; Sync Project with Gradle Files; Invalidate Cashes / Restart; Check xml for errors, restart Studio, etc... I've tried them all.</p>

<p>NONE OF WHICH WORK IN MY SITUATION.</p>

<p>My code is working and without errors because I can create a new Android Studio project, and add my classes and resources. The new Android Studio project will run the the SAME CODE under a different package name.</p>

<p>I encountered this same problem a while back and I vaguely remember deleting something from my project folder (might have been a folder or file). I don't remember what I deleted, but it did fix the problem.</p>

<p>Thanks for any advice.</p>

<p>I finally got Android Studio to build without errors, but honestly I don't know how this happened. It was very puzzling that I could have a project that worked and several copies that didn't (I must have re-created my project 10 times from scratch) each time I would copy the project to an archive directory and start over. One of my build requirements was I needed to compile on Jelly Bean, and I think Android Studio sets some sort of defaults when you open a new project with a Blank Activity. Anyway, each time the R. error occurred the build warning would display this:</p>

<pre><code>&lt;style name="Base.Widget.AppCompat.Spinner.Underlined" parent="android:Widget.Material.Spinner.Underlined
</code></pre>

<p>But my code does not contain a spinner, so I really can't figure out where this is coming from. In fact I've tried to replace files in one of my inoperable saved projects with the files from my working copy (manifests, code, gradle.build, etc.) yet once inoperable, it seems a Studio project will remain that way. </p>

<p>I wish I could reproduce the problem but I cannot.</p>

<p>WTF! After thinking I had resolved this the problem, it is back again. From my working project I did 2 things. Added a very simple activity, and added it's reference to the manifest. Tried to run the project and get the SAME error again, referencing the a spinner. The Gradle build message is:</p>

<blockquote>
  <p>C:\CargoBay\Android\LandApp\app\build\intermediates\res\merged\debug\values-ldltr-v21\values-ldltr-v21.xml
  Error:(3) Error retrieving parent for item: No resource found that
  matches the given name 'android:Widget.Material.Spinner.Underlined'.</p>
</blockquote>

<p>I removed the new code from my project, and it still won't build.</p>

<p>I don't know what to think now.</p>