Java 编辑资源文件时不会构建Android项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1674101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 19:01:46  来源:igfitidea点击:

Android project won't build when editing a resource file

javaandroideclipse

提问by John Lemp

I have an Android 1.5 project in Eclipse and whenever I merely have an xml resource file open the build dies with an error. E.g. if I have the res\layout\main.xmlopen as the active document it won't build and throws the following error:

我在 Eclipse 中有一个 Android 1.5 项目,每当我只打开一个 xml 资源文件时,构建就会出现错误。例如,如果我将res\layout\main.xmlopen 作为活动文档,它将不会构建并抛出以下错误:

Error in an XML file: aborting build.
res\layout\main.xml:0: ERROR Resource entry main is already defined.

Then I have to delete main.out.xmland switch to any .java file in the project to get it to build.

然后我必须删除main.out.xml并切换到项目中的任何 .java 文件才能构建它。

Do I have something configured incorrectly or is this just an Eclipse or ADT bug? It drove me nuts for an hour before I figure out what the cause was.

我是否配置不正确,或者这只是 Eclipse 或 ADT 错误?在我弄清楚原因之前,它让我发疯了一个小时。

采纳答案by Kevin Tighe

I ran into this as well.

我也遇到了这个。

If you have an xml file open and click the 'Run' button, then instead of running your Android project Eclipse will try to run a transform on the xml file. It then creates a new xml file with the output of the transform and adds it to your project. Then the project will fail to run at all because of the existence of the duplicate xml file.

如果您打开了一个 xml 文件并单击“运行”按钮,那么 Eclipse 将尝试对 xml 文件运行转换,而不是运行您的 Android 项目。然后它使用转换的输出创建一个新的 xml 文件并将其添加到您的项目中。那么项目就会因为存在重复的xml文件而根本无法运行。

So make sure you don't have any duplicate xml files in your project (look at the manifest file, as well as layout files). The way I work around this is to make sure the project tree has focus (or just select a tab with a java file) before clicking 'Run'.

因此,请确保您的项目中没有任何重复的 xml 文件(查看清单文件以及布局文件)。我解决此问题的方法是在单击“运行”之前确保项目树具有焦点(或仅选择带有 Java 文件的选项卡)。

There is likely a better way to handle this (via a config change perhaps), but I'm pretty new to Eclipse and that's the workaround I came up with :). Hope that helps.

可能有更好的方法来处理这个问题(也许通过配置更改),但我对 Eclipse 还很陌生,这就是我想出的解决方法:)。希望有帮助。

回答by broschb

You should be able to have the xml file open, and build. There is an option if you right click on the project and go to android to clean up the project or reset the properties. Try that and see if it resolves the issue.

您应该能够打开 xml 文件并构建。如果您右键单击项目并转到android清理项目或重置属性,则有一个选项。尝试一下,看看它是否可以解决问题。

回答by arlen

Eclipce / Project / Clean ... And run your project again ...

Eclipce / Project / Clean ... 并再次运行您的项目 ...

回答by Lance Lefebure

To configure the run button to always run the previously launched application:

要将运行按钮配置为始终运行先前启动的应用程序:

Eclipse -> Window -> Preferences -> Run/Debug -> Launching -> Launch Operation -> Always Launch the previously launched application

Eclipse -> Window -> Preferences -> Run/Debug -> Launching -> Launch Operation -> Always Launch 之前启动的应用程序

回答by Zeus

I just had the same problem because I had two files of different type format, but with the same name, like: jquerymobile.css and jquerymobile.js

我只是遇到了同样的问题,因为我有两个不同类型格式的文件,但名称相同,例如:jquerymobile.css 和 jquerymobile.js

the solution was to rename one of the files

解决方案是重命名其中一个文件

回答by Robert

I had same issue then trying to build project with ant. So I just cleared bin/ directory and the project was build.

我遇到了同样的问题,然后尝试用 ant 构建项目。所以我只是清除了 bin/ 目录,项目就构建好了。

回答by Saravana Kumar Chinnaraj

That will happen in the eclipse Indigo(IDE). when you are trying to run XML file instead of source pages(java files). So that will generate a file with the name of main.out.xml. so we have to delete the main.out.xml file and run the source files..

这将发生在 Eclipse Indigo(IDE) 中。当您尝试运行 XML 文件而不是源页面(java 文件)时。这样就会生成一个名为 main.out.xml 的文件。所以我们必须删除 main.out.xml 文件并运行源文件..

i Hope this will work..

我希望这会奏效..

回答by fshbn

I had the same issue with same named nine-patch and normal images. Giving different names solves the issue.

我对同名的九个补丁和普通图像有同样的问题。给出不同的名字可以解决这个问题。