39

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.xml open as the active document it won't build and throws the following error:

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.xml and switch to any .java file in the project to get it to build.

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.

Korhan Ozturk
  • 11,148
  • 6
  • 36
  • 49
John Lemp
  • 5,029
  • 3
  • 28
  • 36
  • I had the same issue, and it totally freaked me out..., the .xml.out files even caused more and more errors, anybody should mention that problem on developer.android.com thanks anyway!! – f4t-t0ny Nov 10 '11 at 10:04
  • I ran into the same issue.I delete first the xml files which were not parsed main.out.xml and strings.out.xml and then i go clean my project.When i re-run,everything was fine. Rgds, –  Feb 21 '11 at 16:03
  • Well, I have this kind of problem, but simply Project / Clean did works for me. I removed main.out.xml from res/layout, then resaved an main.xml, then reopens project. After this magic, project builds properly. –  Jan 03 '11 at 01:57

8 Answers8

64

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.

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'.

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 :).

starball
  • 20,030
  • 7
  • 43
  • 238
Kevin Tighe
  • 20,181
  • 4
  • 35
  • 36
  • 2
    I had this issue before and I configured to automatically launch the last project, if I press the run button. Thats good because you don't have to remember to change the focus to the correct file/tab. The reason seems to be an XML/XSL issue, which seems to think that the xml files are runable for the XML/XSL extensions. The workaround mentioned by the eclipse guys don't work for me, because I can't remove these plugins. Anyway: Configure your run to run always the last project. Works fine for me with 30+ projects :) – WarrenFaith Aug 22 '10 at 17:46
  • 1
    They REALLY should post this under the Google Tutorial! Thanks, you saved my hair :D – Dany Khalife Jul 26 '12 at 02:18
18

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

Lance Lefebure
  • 6,845
  • 6
  • 24
  • 18
7

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

arlen
  • 1,065
  • 1
  • 16
  • 31
2

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

Robert
  • 3,471
  • 3
  • 21
  • 24
1

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

i Hope this will work..

1

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

the solution was to rename one of the files

Zeus
  • 746
  • 4
  • 18
0

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

fshbn
  • 74
  • 5
0

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.

broschb
  • 4,976
  • 4
  • 35
  • 52
  • If I go to Android Tools-> Fix Project Properties it will work once, but if I switch to another xml resource it fails again. I am definitely not the only one with the issue as I found others discussing it here http://www.anddev.org/viewtopic.php?p=25517 – John Lemp Nov 04 '09 at 15:33
  • Hmm, i'll have to double check when I get home, but I don't recall that error before. Out of curiosity, what version of the SDK are you using and on what OS? I am using 1.6 on Vista. – broschb Nov 04 '09 at 19:33