Android Beginner Top Tip – How to fix the ‘main.out.xml’ issue

Okay if you’re only just beginning Android development, and you’re developing in Eclipse, you will almost certainly run into the following issue at some point. You’ve done ‘something’ and now your project won’t run and you can’t fix it no matter what you do.

The symptoms

You run your application and a weird new file appears in your project explorer called “main.out.xml”.

The application doesn’t build, and on your “Problems” tab in eclipse you get one or more of the following messages;

Premature end of file.	main.out.xml	
Unparsed aapt error(s)! Check the console for output.	
Unknown	Android Packaging Problem

Your console has the following errors in it;

Error in an XML file: aborting build.
main.xml:0: error: Resource entry main is already defined.
main.out.xml:0: Originally defined here.
main.out.xml:1: error: Error parsing XML: no element found

The cause

You’ll get yourself into this state if you attempt to run your code while you’re editing an xml file which aapt uses to generate any source files.

The solution

If you find this page through googling, chances are you’ve been banging your head against the wall because now your project won’t run at all whatever you do. The mistake you made here was to run while the xml file was open. You should only hit that button when a java source file is open. This won’t help you much now though, as trying to run the project will present you with the following error in a dialog box;

Your project contains error(s). Please fix them before running your application

Remedy is very simple though.

  1. Delete the “main.out.xml” file that was created
  2. Select “Clean…” from the “Project” menu
  3. Open a java source file and run again

and the project will run! From now on, only “Run” from a java source code file. I have also found that this solves the “R can not be resolved” error. As a general rule then, if your plugin is getting confused work through the above steps.

Post Mortem

I don’t know *exactly* how aapt is building your “gen” files when you run, but I do know that it uses the xml files to do it, so my current best working theory as to the cause of this problem is that having the file open in the editor puts some kind of lock on the file that prevents the plugin from parsing it correctly. If anyone has any further insights into this problem I’d love to hear them.


37 thoughts on “Android Beginner Top Tip – How to fix the ‘main.out.xml’ issue

  1. holy shit it actually worked.

    there was also a striing.out.xml i had to delete. this problem has been haunting me for weeks and there has been no solution on the android forum, although thousands of newbies are having this issue from the start with the “hello world” program.

    • i can’t believe out of all the “dummies” books and online tuturials i read, including those on the android site itself, not one mentioned “don’t try to run the project while the main.xml file is open”. i bet a lot of budding andriod app development carreers were killed by this issue from the start, mine almost was.

  2. Wow,.. this must be the first IDE on which I got such a problem… can’t run the project while the XML is open???
    Thanks man, been stuck for an hour and was gonna stop programming soon!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s