Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
332 views
in Technique[技术] by (71.8m points)

android - "R cannot be resolved" may have wrong build path or libraries import

I know this question has been many times but trust me I have checked all. Most of the question suggests to remove import android.R , remove any error in the xml file, checking name of the files (no capital letters) then rebuild and clean the project or restart eclipse. I have tried all but none solved the problem. The problem occured when i cleaned all the projects. Now all the projects are showing that error. Since all the project were running perfectly before i cleaned projects, there is no possibility that all of the sudden the layouts or the file names of all the projects have error in them.

Also there is no file in gen folder. As far as i can understand there is something wrong with the build path or preferences can anyne point me in a correct direction? o!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Check the answer here and the thread here. Check if your layouts contain any errors (this has to be done manually or automatically only with Android Studio). Search for incorrectly closed tags like <string> - </string>.

EDIT (taken from this thread):

Cleaning a project removes all auto-generated files. Building the project it should automatically create them. When you Clean a project, there's an option to start a build immediately after clean up.

Here's a few things you can try (did the same procedure after manually deleting the "gen" directory.

  • After you have deleted the gen directory, go to Project > Clean ...
  • You should have errors indicating that R cannot be resolved to a variable. Right click on your project from the Package Explorer and select Build Project. Be sure Build Automatically option is turned off (uncheck in Project > Build Automatically).
  • Errors regarding R should have now disappeared. Now, perform a Project Clean once again. All errors should be gone.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...