This compilation error means the android sdk is looking for the build.xml file which is inside the folder sdk.dir/tools/ant. The compiler cannot find it, hence the error.

When a project is created, one of the files generated by the bootstrap process is build.xml. The Apache Ant build tool will look for it on the top most folder of the project. This build file does not contain all the information it needs to compile and make a project. It references another build file which is found on sdk.dir/tools/ant/build.xml.

The compiler will resolve the value of sdk.dir by looking it up inside the local.properties file, which, like the build.xml, is also located on the root folder of the project. sdk.dir needs to point to the directory where you installed the android software development kit.

The code snippet below is the content of the local.properties file of a sample project.

# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.

# location of the SDK. This is only used by Ant
# For customization when using a Version Control System, please read the
# header note.

sdk.dir=/Users/ted/progtools/android-sdk-macosx

The local.properties file is also generated as part of project creation process. The value of the sdk.dir inside the local.properties is inferred by the android tools, and it always gets it right. You do not need to mess around with local.properties. Usually.

How to fix it

Open the local.properties file. Inspect the contents of the file. Verify that the value of sdk.dir is really pointing to the folder where you installed the android sdk.

Next, fix the value of sdk.dir. You can try to change the sdk.dir value by directly editing local.properties, but did you see the commented section of local.properties? It said don’t mess around with it. Your changes will be overwritten.

Then, update the project so you can restore the value of sdk.dir. Use the android command line tools for this

cd ~/project_path
android update project --path .

There is a period at the end the command snippet above. It may not be visible on the screen but it is there. After running the project update command, the sdk.dir value will be fixed. Open the local.properties file to verify.

Next, inspect your .gitignore file. The local.properties file must unique to your machine setup. One of the reasons why the sdk.dir is messed up is because the local.properties file in your project is not really yours. It probably belongs to somebody else and it got into your machine because you pulled the project from a source code repository.

If you are using git, add the local.properties file to the .gitignore file so the next time you push or pull from a repository, the local.properties will be ignored by git