简体   繁体   中英

R.java is missing on a clean Android Project

I'm creating a clean project on ADT and I noticed that the gen folder is empty (with no R.java in it), not letting me run the project. I'm running ADT with all stuff up-to-date (as you can see here)

https://dl.dropboxusercontent.com/u/48232925/android.png

I already cleaned and built it in every possible way. I also tried to reimport the project, and nothing. There are no errors in the XML files.

I searched for a solution and I found a lot of people with the same problem, and in most cases the solution was to update the SDK tools, but it didn't work for me.

Is there a reason for this?

at the top of screen, click build -> rebuild project Give it a few seconds. it worked for me, i hope it save you aswell im using Android Studio(beta) 0.8.9

My R disappeared after i fiddled with sound files in my res/raw directory(converted them to different formats, figuring out how SoundPool class works...and suddenly there is red "R"'s everywhere!

Try right clicking on the project, then going to Android Tools > Fix Project Properties.

If that doesn't work, then try cleaning it before and possibly after that.

如果R.java消失,您通常必须再次从头开始重新创建项目。

There are many reasons for R.java missing issue, i use to face this issue frequently, some of my thoughts to debug this issue.

  • Try creating another test project using File->New->Project->Android->Android Application Project. After creating the project run the project in emulator. If every thing works then your setup is perfect.

  • Check your imports section of your java files, some times default R.java gets included which is from android package. In this case Remove that import and add correct import statement.

  • Check your "res" folder all the xml's should be well formed and valid.

Hope these debugging steps may help to find the root cause.

try deleting the r.java file in gen folder. when you run again after cleaning and building the project. It should recreate those files and it should work after that. Try that. Other wise you might have to reinstall Eclipse as you have tried in so many different projects

Something I just noticed was that after I removed the auto-generated code for the menus (which I wasn't using) it started causing errors. Eventually when I cleaned with the menu xml's still in the file structure, my R file disappeared. I removed all entries in the menu folder and then cleaned again. This worked for my specific instance. Hope this helps others as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM