简体   繁体   English

gen已存在但不是源文件夹

[英]gen already exists but is not a source folder

I am developing my Android project, After I removed a unused library, I got the error: 我正在开发我的Android项目,在我删除了一个未使用的库后,我得到了错误:

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. 在我的Activity代码中,无法解析R.java所有资源。

I tried, right click on my project => Java Build Path => under "Source" tab, I added gen/ as source. 我试过,右键单击我的项目=> Java Build Path =>在“Source”选项卡下,我添加了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." 我发现,eclipse还抱怨“Project没有project.properties文件!编辑项目属性来设置一个。” , but I do have project.properties file under my project. ,但我的项目下有project.properties文件。 Why it complains? 为什么抱怨? I have cleaned the project and "fix project properties" but it does not help. 我已经清理了项目并“修复项目属性”,但它没有帮助。

I get the same problem. 我遇到了同样的问题。

Two actions, first: 两个动作,第一个:

    1.Right click on the project and go to "Properties" 1.右键单击项目并转到“属性”
    2.Select "Java Build Path" on the left 2.在左侧选择“Java Build Path”
    3.Open "Source" tab 3.打开“源”选项卡
    4.Click "Add Folder..." and check "gen" and "src" 4.单击“添加文件夹...”并选中“gen”和“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" 1.右键单击项目并转到“属性”
    2. Select "Java Build Path" on the left 2.选择左侧的“Java Build Path”
    3. Open Libraries "tab" 3.打开库“选项卡”
    4. Add an external JAR. 4.添加外部JAR。 Add the Google API that is in your android directory (android-sdk\\platforms\\android-yourversion 添加Android目录中的Google API(android-sdk \\ platforms \\ android-yourversion

And now it works for me! 现在它对我有用!

Solution : 方案:

Step 1 : 步骤1 :

  • Right click on the project and go to "Properties" 右键单击项目并转到“属性”
  • Select "Java Build Path" 选择“Java Build Path”
  • Switch to "Source" tab Remove all sources from source folder on Build Path 切换到“源”选项卡从“构建路径”上的源文件夹中删除所有源
  • Restart Eclipse 重启Eclipse

Step 2 : 第2步 :

  • Right click on the project and go to "Properties" 右键单击项目并转到“属性”
  • Select "Java Build Path" 选择“Java Build Path”
  • Switch to "Source" tab 切换到“来源”标签
  • Click "Add Folder..." and check "gen" and "src" source folder on Build Path 单击“添加文件夹...”并在构建路径上选中“gen”和“src”源文件夹
  • Restart Eclipse 重启Eclipse

Final 最后

Build Project(s) 建设项目

Happy Coder :) 快乐的编码器:)

  1. Right click on the project and go to Properties 右键单击该项目,然后转到“ 属性”
  2. Select Java Build Path on the left 选择左侧的Java Build Path
  3. Open Source tab 开源”选项卡
  4. Click Add Folder... and check gen and src 单击添加文件夹...并检查gensrc

This is caused by using the wrong importer in Eclipse. 这是因为在Eclipse中使用了错误的导入程序。 If you have Android projects, you need to import them into your workspace with Android->Existing Android Code , not General->Existing Projects . 如果您有Android项目,则需要使用Android->现有Android代码将其导入工作区,而不是通用 - >现有项目

在此输入图像描述

i had to delete the entire gen folder within eclipse not from file explorer. 我不得不删除eclipse中的整个gen文件夹而不是文件资源管理器。 then did a clean and it was rebuilt. 然后干净了,重建了。 funny this occured right after i ran a Lint HTML report. 搞笑这是在我运行Lint HTML报告后发生的。

The gen folder is where ADT creates the R.java file, which specifies your resource definitions. gen文件夹是ADT创建R.java文件的位置,该文​​件指定了您的资源定义。 ie your resources (colours, dimensions, layouts, etc) are converted to code, and placed in R.java in the gen folder. 即您的资源(颜色,尺寸,布局等)转换为代码,并放在gen文件夹中的R.java中。

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. 因此,当您构建应用程序时,您需要确保IDE将gen文件夹视为源代码文件夹,因为它包含R类。

In your IDE, you need to mark the gen folder as a source folder, so its content are built alongside your source. 在IDE中,您需要将gen文件夹标记为源文件夹,因此其内容与源代码一起构建。

Your acceptance rate is very low. 你的录取率很低。 If you want people to help you, you need a high acceptance rate. 如果您希望别人帮助您,您需要很高的接受率。

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. 在包资源管理器中,右键单击gen文件夹,找到“构建路径 - 用作源文件夹”并单击它。

That is it. 这就对了。 I hope it will help. 我希望它会有所帮助。

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. 我为具有相同问题的项目配置了SVN,删除了所有文件夹和文件,从SVN再次检索它仍然没有运气。 The only thing that helped was reverting the changes, and deleting/re-importing projects to the workspace. 唯一有帮助的是恢复更改,删除/重新导入项目到工作区。 Hope this helps 希望这可以帮助

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. 一旦我关闭Eclipse并重新启动,问题就消失了。

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. 我发现我在drawable目录中有两个冲突的文件:icon.png和icon.xcf。 This made R fail generation. 这使得R失败了。 I moved the icon.xcf out of the way and R generated and the project compiled. 我将icon.xcf移开了,生成了R并编译了项目。

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. 转到项目属性,然后转到Java Build Path,然后删除已存在的文件夹,然后单击Add Folder,然后添加Source和gen文件夹。 then Press ok............It will work....... 然后按确定............它会工作.......

My solution was to paste the following into the .classpath file: 我的解决方案是将以下内容粘贴到.classpath文件中:

<?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>

我们还需要检查我们的import语句,如果我们已导入'android.R'必须删除它。

This happens because your .classpath file got wiped out somehow. 发生这种情况是因为你的.classpath文件以某种方式被删除了。 This file contains all the information from the Java Build Path tab under Project Properties. 此文件包含“项目属性”下“Java构建路径”选项卡中的所有信息。 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. 如果您的计算机上有.classpath文件的副本,则只需将其复制并粘贴到项目目录中即可。

I tried the suggestions given here and still had the problem. 我尝试了这里给出的建议,但仍然遇到了问题。 Finally, it turned out that Eclipse got its imports wrong. 最后,事实证明Eclipse的导入错误。 For some reason it added the words "gen" and "src" to the beginning of the import line. 由于某种原因,它在导入行的开头添加了“gen”和“src”。 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. 一旦我这样做,一切都恢复正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM