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.
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
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.
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.
- Delete the “main.out.xml” file that was created
- Select “Clean…” from the “Project” menu
- 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.
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.