Magic behind R.java file

46,991

Solution 1

I found the problem - I have created a 9patch image with the patch area defined only on the Y axis (I was trying to prevent resizing on the other one).

The question remains: Why isn't there a warning about the error? Or if there is - where is it buried?

Solution 2

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!

Solution 3

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.

Solution 4

I had this problem several times, and most of the times it is caused by some mistake in the "res" files, check everything is OK in all your res files, mainly XML, and after you can built.

For example, two common causes of this problem can be:

  • Didn't properly spell the name of a property in a Style in a XML file.

  • Didn't properly close a string in the XML of a locale file.

Solution 5

Sorry, but try to check the output in Eclipse. May be you have some errors that prevents Eclipse to finish build proccess(check your AndroidManifest.xml, is it correct?).I mean, that you should check all your resource files(string.xml, layouts, ...) and interfaces(*.aidl), may be there are some problems(inconsistent syntax, or something....) that prevent eclipse to generate R.java.

Share:
46,991
LambergaR
Author by

LambergaR

Freelance Android dev and a total mobile freak :)

Updated on September 07, 2020

Comments

  • LambergaR
    LambergaR almost 4 years

    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 :)