Developing for Android in Eclipse: R.java not rege

2018-12-31 01:38发布

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 a new one. But that didn't happen, and I don't have R.java now. How can I regenerate one?

I'm using Windows 7.

From one of the comments: "Doing Project -> Clean is what caused the problem for me. Cleaning deletes R.java...and for whatever reason the plugin is not regenerating the file."

30条回答
柔情千种
2楼-- · 2018-12-31 01:41

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.

查看更多
不再属于我。
3楼-- · 2018-12-31 01:41

I changed my layout XML file name and found out later that of the XML file (widget provider in this case) still refers to the old layout XML which doesn't exist, and that prevented the auto generation/correction of R class.

查看更多
弹指情弦暗扣
4楼-- · 2018-12-31 01:43

You 100% have an error in an XML-file, but the XML verification does not show you the error. This is the reason why you need to check your XML files first!

查看更多
余生无你
5楼-- · 2018-12-31 01:44

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.

查看更多
零度萤火
6楼-- · 2018-12-31 01:44

R.java will never be generated if there are any errors in the res folder. For example, in the drawable subfolder there are two files which have the same name, one is icon.png and the other is icon.html.

You can see some error in the Eclipse console log window which is saying "Resource entry icon is already defined.". After deleting icon.html, you can clean or just delete the gen folder. You will find that R.java is created.

查看更多
倾城一夜雪
7楼-- · 2018-12-31 01:44

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.

查看更多
登录 后发表回答