Adding android library project to an android project prevents Ant from building-ThrowExceptions

Exception or error:

I’m adding an android library project to my android app (in this case, Beintoo). It’s not mine; It’s an external library. However, it doesn’t come with a build.xml. Building in Eclipse works fine, but when I attempt to build my app with ant, I get this:

BUILD FAILED
C:\Sandbox\MyProject\build.xml:110: The following error occurred while executing this line:
C:\Sandbox\MyProject\build.xml:41: The following error occurred while executing this line:
C:\Program Files (x86)\Android\android-sdk\tools\ant\build.xml:515: Invalid file: C:\Git\Beintoo-Android\beintoo-android-sdk\BeintooSDK\build.xml

It’s perfectly true. The file is invalid, because it doesn’t exist. I wouldn’t know what to do to add it safely, nor if that’s even a good idea.

I have learnt that I can’t simply build the library project into a jar. How can I get my project to build in Ant with this library project?

How to solve:

Ok, so, Error 454’s answer was close, but not quite right. Since r14 of Android Tools, every library project must have it’s own build.xml if it is to be built by Ant, as noted here:

https://groups.google.com/forum/?fromgroups#!topic/adt-dev/Z2e3dY-3Ma0

Running android update lib-project (which, as Error 454 notes, is in the android-sdk/tools folder which should be in PATH) on the library project will add a generic build.xml, and allow the main project to build.

###

For library projects, you need to browse to the library project root and run:

android update lib-project -p .

The android executable is in the android sdk/tools folder which should be added to your path variable in your OS. Once you run this, the necessary build files will be generated and your ant build should succeed.

Similarly, if your root project doesn’t have the necessary build files, you will need to browse to the main project root and run:

android update project -p .

###

Additionally to the two previous correct answers I had to add –target android-16 because I was getting an “Error: The project either has no target set or the target is invalid.”

So in my case

android update lib-project -p . --target android-16

Did it. (replace the 16 as you need)

Leave a Reply

Your email address will not be published. Required fields are marked *