gen already exists but is not a source folder

2019-01-30 02:57发布

I am developing my Android project, After I removed a unused library, I got the error:

myproject/gen already exists but is not a source folder. Convert to a source folder or rename it

In my Activity code, all resources from R.java can not be resolved.

I tried, right click on my project => Java Build Path => under "Source" tab, I added gen/ as source. But it does not help with the problem...

Why, how to get rid of this problem?

----UPDATE----

I found that, the eclipse also complain that "Project has no project.properties file! Edit the project properties to set one." , but I do have project.properties file under my project. Why it complains? I have cleaned the project and "fix project properties" but it does not help.

15条回答
The star\"
2楼-- · 2019-01-30 03:14

I had some of the same symptoms, but solved it differently:

I found out that I had two files in the drawable dir that were conflicting: icon.png and icon.xcf. This made R fail generation. I moved the icon.xcf out of the way and R generated and the project compiled.

查看更多
Anthone
3楼-- · 2019-01-30 03:14

We also need to check our import statements, If we have imported 'android.R' got to remove that.

查看更多
Animai°情兽
4楼-- · 2019-01-30 03:15

The gen folder is where ADT creates the R.java file, which specifies your resource definitions. i.e. your resources (colours, dimensions, layouts, etc) are converted to code, and placed in R.java in the gen folder.

So when you build the app you need to ensure the gen folder is treated as a source code folder by your IDE, as it contains the R class.

In your IDE, you need to mark the gen folder as a source folder, so its content are built alongside your source.

Your acceptance rate is very low. If you want people to help you, you need a high acceptance rate.

查看更多
兄弟一词,经得起流年.
5楼-- · 2019-01-30 03:21
  1. Right click on the project and go to Properties
  2. Select Java Build Path on the left
  3. Open Source tab
  4. Click Add Folder... and check gen and src
查看更多
贪生不怕死
6楼-- · 2019-01-30 03:25

This happens because your .classpath file got wiped out somehow. This file contains all the information from the Java Build Path tab under Project Properties. You could add in all information manually but there's an easier way of fixing this problem.

If you have a copy of the .classpath file on your machine, you can just copy and paste it into your project directory.

查看更多
淡お忘
7楼-- · 2019-01-30 03:26

i had to delete the entire gen folder within eclipse not from file explorer. then did a clean and it was rebuilt. funny this occured right after i ran a Lint HTML report.

查看更多
登录 后发表回答