92

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.

Leem.fin
  • 40,781
  • 83
  • 202
  • 354
  • 5
    check your src folder contains any gen folder. if there delete it. .no need to create it manuallly. Clean your project once. – Padma Kumar Mar 02 '12 at 11:02
  • hi, My src folder does not contain any gen folder... – Leem.fin Mar 02 '12 at 12:00
  • 1
    Happened to me after importing a project – Habizzle Nov 04 '13 at 10:24
  • 1
    You have a very good answer, currently rated 79, yet you haven't accepted it. You should accept it. And your "UPDATE" should be a separate question (and you might want to see if anyone has already answered it). – steveha Jan 07 '14 at 21:10
  • I think my answer will help in this problem.. http://stackoverflow.com/questions/9738203/eclipse-android-gen-already-exists-but-is-not-a-source-folder/22346099#22346099 – Ranjit Mar 12 '14 at 08:43
  • I had this happen after mistakenly adding Project.Properties to the .gitignore file when setting up my Git repository. – Rben Jan 28 '15 at 20:25

15 Answers15

234

I get the same problem.

Two actions, first:

    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"

second: (because the previous action asked me to remove something... I do not remember what it was...)

    1. Right click on the project and go to "Properties"
    2. Select "Java Build Path" on the left
    3. Open Libraries "tab"
    4. Add an external JAR. Add the Google API that is in your android directory (android-sdk\platforms\android-yourversion

And now it works for me!

AntoineP
  • 3,035
  • 1
  • 19
  • 22
37

Solution :

Step 1 :

  • Right click on the project and go to "Properties"
  • Select "Java Build Path"
  • Switch to "Source" tab Remove all sources from source folder on Build Path
  • Restart Eclipse

Step 2 :

  • Right click on the project and go to "Properties"
  • Select "Java Build Path"
  • Switch to "Source" tab
  • Click "Add Folder..." and check "gen" and "src" source folder on Build Path
  • Restart Eclipse

Final

Build Project(s)

Happy Coder :)

Vinayak
  • 6,056
  • 1
  • 32
  • 30
17
  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
Ely
  • 10,860
  • 4
  • 43
  • 64
Shubham Das
  • 1,257
  • 11
  • 10
8

This is caused by using the wrong importer in Eclipse. If you have Android projects, you need to import them into your workspace with Android->Existing Android Code, not General->Existing Projects.

enter image description here

Eric Cloninger
  • 2,260
  • 2
  • 21
  • 26
3

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.

j2emanue
  • 60,549
  • 65
  • 286
  • 456
  • This also worked for me. Just deleted the gen file, and a few seconds later is was regenerated and everything is back to normal. – Sandy Nov 14 '13 at 15:45
2

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.

Ollie C
  • 28,313
  • 34
  • 134
  • 217
  • 9
    but how can I accept if there is no correct answer? I do check the answers, but no one is the solution... For example, my current post, I know what is gen/ and how it works in Android, I am seeking a solution to my current problem. But not yet have one. – Leem.fin Mar 02 '12 at 12:06
1

I met the same problem, solved it as following:

In Package Explorer, right-click the gen folder, find "Build Path - Use as Source Folder" and click it.

That is it. I hope it will help.

hywl51
  • 551
  • 1
  • 5
  • 13
1

I had SVN configured for a project with the same problem, deleted all folders and files, retrieved it again from SVN and still no luck. The only thing that helped was reverting the changes, and deleting/re-importing projects to the workspace. Hope this helps

milosmns
  • 3,595
  • 4
  • 36
  • 48
0

The last time I had this issue, it was because I switched the source to another branch behind the scenes. Once I closed Eclipse and relaunched, the issue went away.

themarshal
  • 1,056
  • 1
  • 11
  • 20
0

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.

Stephan Henningsen
  • 3,665
  • 1
  • 22
  • 29
0

Go to the project properties then Go to Java Build Path then Remove already exist folder then Click Add Folder then Add the Source and gen folder. then Press ok............It will work.......

Singhak
  • 8,508
  • 2
  • 31
  • 34
0

My solution was to paste the following into the .classpath file:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
    <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="src" path="gen"/>
    <classpathentry kind="output" path="bin/classes"/>
</classpath>
A.G.
  • 2,037
  • 4
  • 29
  • 40
0

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

Jehoshuah
  • 671
  • 2
  • 9
  • 20
0

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.

Patrick
  • 11,552
  • 7
  • 29
  • 41
0

I tried the suggestions given here and still had the problem. Finally, it turned out that Eclipse got its imports wrong. For some reason it added the words "gen" and "src" to the beginning of the import line. I had to change all the import lines from

import gen.org.qtproject.qt5.android.bindings.QtApplication;

to

import org.qtproject.qt5.android.bindings.QtApplication;

Once I did that, everything came back to normal.

panonski
  • 555
  • 5
  • 10