Developing for Android in Eclipse: R.java not regenerating

前端 未结 30 3069
孤城傲影
孤城傲影 2020-11-21 07:04

I\'ve found out that my R.java is never updated, so it doesn\'t contain information about my new resources, so I decided to delete it and thought that Eclipse would generate

相关标签:
30条回答
  • 2020-11-21 08:01

    Quick fix:

    The package name in the manifest needs to be the same as the one in the /src folder, the /gen folder package will be automatically reproduced.

    Detailed observation:

    Observe the name of package in the /gen folder. In my case it was different than the one in the /src folder.

    The package referenced in the manifest was that of the /gen folder.

    I attempted to add a package with the name of the /src folder to the /gen folder too see what would've happened, but this did not solve the issue. I proceeded then to remove the package name that was not the same as the package name of the /src folder. This package with the name that did not correspond to the /src folder was recreated as soon as I removed it.

    Since the package reference in the manifest corresponded to the one that was being senselessly recreated and that did not correspond with the package in the /src folder, this prompted to rename package = "oldPackage" with the package = "srcFolderPackage".

    0 讨论(0)
  • 2020-11-21 08:03

    All of these answers could not work if you use Maven. The solution for me was to add

    <genDirectory>${project.basedir}/gen</genDirectory>
    

    to the configuration section of android-maven-plugin.

    0 讨论(0)
  • 2020-11-21 08:04

    If your R.java isn't getting generated, one of the solutions is to delete the layout file named "blabla.out.xml".

    After deleting this file, try cleaning the project from menu Project -> Clean.

    0 讨论(0)
  • 2020-11-21 08:04

    I've found that any file that has capital letters in the res folder will create this error. This happened to me with a PNG file I added and forgot about.

    0 讨论(0)
  • After reading through many posts and YouTube videos, I found that each of us have R.java missing for different reasons.

    Here's how I fixed this in Eclipse:

    • Create R.java in gen folder manually and save.
    • After that go to Project and click "Clean"

    The following message will display and your file will automatically be rewritten:

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

    0 讨论(0)
  • 2020-11-21 08:05

    As a generalization of Glaux's answer, if you have any errors in the res directory, then R.java may not generate - even if you clean and rebuild. Resolve those errors first.

    As an example: when you add an image file of say, "myimage-2.jpg", the system will consider this an error, since file names are limited to alphanumeric values. Do a refresh on your 'res' directory after adding any files and watch the output in your console window for any file name warnings.

    0 讨论(0)
提交回复
热议问题