20

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?

AlbeyAmakiir
  • 2,217
  • 6
  • 25
  • 48

3 Answers3

32

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.

AlbeyAmakiir
  • 2,217
  • 6
  • 25
  • 48
  • 3
    Great answer! More specifically I had to run "android update lib-project -p ." from within the library project. This generates build.xml and proguard-project.txt. – runamok Nov 05 '13 at 21:14
19

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 .
Error 454
  • 7,255
  • 2
  • 33
  • 48
  • I discovered and ran "android update lib-project" on the library project, which seemed to help, but not totally succeed. Doing your solution on the app is throwing a NullPointerException, so until I figure that issue out, I can't tell how successful it is in normal situations. – AlbeyAmakiir Jul 02 '12 at 06:29
2

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)

tru7
  • 6,348
  • 5
  • 35
  • 59