Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magic behind R.java file

Recently I have been having quite some problems with R.java file. Now I have decided to do a backup and delete the file to see what happens.

Nothing happened, so I created an empty R.java file and hoped for the best. Now Eclipse seems to figure out that the file was tampered with and even issues a warning:

R.java was modified manually! Reverting to generated version!

And that's all there is. I tried building it manually but got no results.

So, I have two questions:

  1. what should I do to force Eclipse to regenerate the file
  2. what is happening here? How is the file created, where is the code that is generating the file?

I would appreciate any help. As usual the problem occurred just a few days before the deadline :)

like image 229
LambergaR Avatar asked Jan 12 '10 11:01

LambergaR


People also ask

What is R file in Java?

Android R. java is an auto-generated file by aapt (Android Asset Packaging Tool) that contains resource IDs for all the resources of res/ directory. If you create any component in the activity_main. xml file, id for the corresponding component is automatically created in this file.

How do I delete a file in R Java?

Close your app in an Android Studio/Eclipse . Go to your workspace where you have the project. Open that R. jave file in notepad and remove the "/" symbol then save it.


2 Answers

I had a problem getting my Android app to compile, with seemingly inexplicable errors about failure to generate R.java.

The problem was caused by my previously killing the Android emulator during the build. Don't do that! A clue was the appearance of several left over *.out.xml files.

The solution was to select the project, click Project->Clean, and then manually delete all the *.out.xml files. Only then could I click Run->Run and have a successful build.

One more thing: I'm using Eclipse. I had to make sure that the project was selected in Package Explorer, and not just some random source file. Easy to not notice!

like image 148
Stan Mohler Jr. Avatar answered Oct 20 '22 05:10

Stan Mohler Jr.


R.java is autogenerated on build. It's content is based on the resource files (including layouts and preferences).

When you deleted it, it was recreated, but if you create your own, you will get into trouble as the build system will not replace it.

You can simply delete it again (manually or by choosing Project->Clean) and rebuild your program.

like image 38
Tomas Avatar answered Oct 20 '22 05:10

Tomas