vnshetty
vnshetty

Reputation: 20132

How to generate an R file in Android

I have a sample app with source code. It contains all Java files, but the R file is not present in the gen folder. How can I generate it?

Upvotes: 1

Views: 17928

Answers (6)

user2602569
user2602569

Reputation: 1

Go to the gen folder in your package explorer and create a blank R.java file. Then fix the errors in other file and refresh. If it doesnt work try restarting eclipse. It should work, I had the same problem and fixed it this way.

Upvotes: 0

AndroidDev
AndroidDev

Reputation: 21237

You also might check your console output. I had a similar issue that I traced back to this error in the console:

Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead. Please use Android Tools > Fix Project Properties.

It was easily fixed by right clicking the project properties (in the Package Explorer), then selecting Android Tools -> Fix Project Properties (as suggested by the error message). That solved the whole issue. The R file was then generated and everything was fine.

Upvotes: 0

user529543
user529543

Reputation:

Altought it is an accepted answer, but maybe it will help for somebody else, who is looking for this question:

The R file it is not generated, if you have syntax error in res folder. Those can be the above mentioned, but can be a copy - paste error for an image copied from the iPhone app folder. Right now I have that error: myImage.png is not allowed to be in res/drawable, because of his name! Need to rename the time to my_image.png and that will be ok, just a clean and with automatic build checked will be all fine.

If doesn't exist the resource in xml will see an error:

not existing resource on that care there are no R file, but after is corrected than it is: corrected

  • here it was the emptyList and the file it was emptyList.png

I met some String resources encoding problems a few years ago, forgot the case and how it was the code exactly. But if no R file and after Clean, Build there isn't it means the compiler-linker? (don't know the android tool name) can't produce the R file based on what have you in project settings and the res folder. Can be layout, strings, animations, anything else, what is under res folder.

enter image description here

Upvotes: 3

James Harris
James Harris

Reputation: 11

Clean and Build the application from eclipse. If that doesn't work, there possibly syntax errors or resource not found errors. Search through your console for details and fix those errors until all are resolved. Eclipse will immediately generate the resource file (R.java) once done.

Upvotes: 1

Krishna
Krishna

Reputation: 1861

Usually it is autogenerated. If it is not, it could be because of a syntactic error in Layout.xml. Look at the project errors.

Upvotes: 1

Prasham
Prasham

Reputation: 6686

Clean And Build the application from eclipse Project Menu or CTRL+B is the shortcut key, it will automatically generate R.java file.

Upvotes: 2

Related Questions