0

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.

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

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.

NONE OF WHICH WORK IN MY SITUATION.

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.

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.

Thanks for any advice.

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:

<style name="Base.Widget.AppCompat.Spinner.Underlined" parent="android:Widget.Material.Spinner.Underlined

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.

I wish I could reproduce the problem but I cannot.

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:

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

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

I don't know what to think now.

user2254532
  • 1,851
  • 2
  • 14
  • 14
  • Also manual deletion of all 'build' folders dosen't help ? – Andre Classen Jan 10 '16 at 13:14
  • can you try deleting "bin" and "gen" and clean build ? – Amod Gokhale Jan 10 '16 at 13:17
  • when I delete the "build" folder, Studio just replaces it and R. still can't be resolved. ..Sorry I don't know what "bin" and "gen" are referring to (no folders of files found with those names). – user2254532 Jan 10 '16 at 13:34
  • 6
    please review my answer http://stackoverflow.com/questions/17054000/cannot-resolve-symbol-r-in-android-studio/30015419#30015419 – Mina Fawzy Jan 10 '16 at 14:08
  • This usually happens when one of your XML resources is wrong. I find it hard to believe that it works if you make a new project and copy *everything* over. If that's the case, though, it sounds like you just aren't building the project – OneCricketeer Jan 10 '16 at 14:37
  • did u tried to import the R file.? – Mr Robot Jan 10 '16 at 15:04

1 Answers1

0

In Android Studio select your project folder, go to VCS / Local History / Show History. Show History will list any files that were moved or deleted, and give you an option to restore the file. If you select your main activity code, it shows the history of code changes, and you can restore to previous code that was working.

enter image description here

Greg Marsh
  • 209
  • 1
  • 2
  • 9