Android SDK: Error in an XML file: aborting build

I just started Android programming using the Android Development Tools (ADT) plugin for the Eclipse IDE, and while experimenting with layout weights, I came across a weird error after running the program.
The console dump showed this :

2011-09-25 14:21:10 - HelloLinear] Error in an XML file: aborting build.
[2011-09-25 14:21:11 - HelloLinear] res\layout\main.xml:0: error: Resource entry main is already defined.
[2011-09-25 14:21:11 - HelloLinear] res\layout\main.out.xml:0: Originally defined here.
[2011-09-25 14:21:11 - HelloLinear] C:\Users\Mukul\workspace\HelloLinear\res\layout\main.out.xml:1: error: Error parsing XML: no element found

Also, I noticed that there was a new XML file called main.out.xml created in the res\layout\ folder.
The reason you might get this error is that when you run the program you might have the main.XML file open as the active file. Eclipse (presumably) tries to run the XML file as the android application rather than the class file.  The solution to this is pretty simple

1. Delete the main.out.xml file (generated during runtime). You’ll find it in the res\layout folder
2. After you are done editing the main.XML file, save it and switch the view to the java file which is accessing the main.xml that you’ve edited
3. Run the program and voila! – the error disappears

Update: Here’s a fix that does not require you to switch views every time: Eclipse -> Window -> Preferences -> Run/Debug -> Launching -> Launch Operation -> ‘Always Launch the previously launched application’. You still need to delete the xml out files that were created and make sure you have  run the correct configuration at least once. Credit for this goes to Gnac of Stack Overflow

3 Responses to “Android SDK: Error in an XML file: aborting build”


  1. Fatal error: Uncaught Error: Call to undefined function ereg_replace() in /home/mukulhi2/public_html/wp-content/themes/swatch/includes/theme-comments.php:63 Stack trace: #0 /home/mukulhi2/public_html/wp-content/themes/swatch/includes/theme-comments.php(19): the_commenter_link() #1 /home/mukulhi2/public_html/wp-includes/class-walker-comment.php(174): custom_comment(Object(WP_Comment), Array, 1) #2 /home/mukulhi2/public_html/wp-includes/class-wp-walker.php(145): Walker_Comment->start_el('', Object(WP_Comment), 1, Array) #3 /home/mukulhi2/public_html/wp-includes/class-walker-comment.php(135): Walker->display_element(Object(WP_Comment), Array, '5', 0, Array, '') #4 /home/mukulhi2/public_html/wp-includes/class-wp-walker.php(370): Walker_Comment->display_element(Object(WP_Comment), Array, '5', 0, Array, '') #5 /home/mukulhi2/public_html/wp-includes/comment-template.php(2097): Walker->paged_walk(Array, '5', 0, 0, Array) #6 /home/mukulhi2/public_html/wp-content/themes/swatch/comments.php(31): wp_list_comments('avatar_size=40&...' in /home/mukulhi2/public_html/wp-content/themes/swatch/includes/theme-comments.php on line 63