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

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?

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)

Related

How do I add the appcompat library to an android project in netbeans?

I have the support libraries installed via the SDK manager.
I have copied the C:\Program Files\Android\android-sdk\extras\android\support\v7\appcompat folder to my projects libs folder.
I have added the \tools folder of the sdk to my command line path. I have then run
android update project --path . --library C:\Users\srayner\dev\android\AndroidTest1\libs\appcompat
But now netbeans gives me this error;
Failed to resolve library path: C:\Users\srayner\dev\android\AndroidTest1\libs\appcompat
What is the correct method to setup an android support library with resouses in netbeans?
I have successfully build and added the appcompat project in NetBeans.
Create a new android project in netbeans - I called mine "appcompat".
Build your new project just make sure it can be successfully build.
Delete everything inside the src directory and rebuild. My project just contained the default MainActivity that was created by NetBeans. You don't need it.
Navigate to your android sdk install directory
"androidSdkPath\extras\android\support\v7\appcompat and copy all
the contents within that folder
Paste the copied contents to the android project that you
created in step 1 (again mine was named as appcompat).
Very important - Open project.properties and ensure that the "target" property matches the following: "target=android-21"
Build your project and Voila... you should be all set.
If you are still having issues compiling the project that will be using the appcompat library, change your project library properties target=android-21"

Android test project fails to build under Ant, OK in Eclipse

I am trying to set up a CI build server for an Android app project and its JUnit test project. I've generated the appropriate build.xml files for both app and test projects.
Both projects build and execute fine under Eclipse.
However, when I try to do ant debug on the test project without having first built both projects with Eclipse, I get several [javac] errors saying error: cannot find symbol which refer to classes in the app project.
I think this is a difference between the classpath that Eclipse sees and the classpath that Ant is using...
How do I tell Ant where to find the app classes?
It seems the Android default build.xml defines all the targets, so I was wondering how to insert the appropriate reference in the app project's build.xml... rather than having to start the build file from scratch.
Tried exporting the Ant build file from Eclipse; that fails to build either project.
What seems to work is to re-run:
android update test-project -m ../../app_project/ -p .
within the test project.
The only change it made was to create an ant.properties file with one non-comment line:
tested.project.dir=../../app_project/
And now it all works swimmingly outside of Eclipse!

library resolve to a path with no project.properties file

I'm having trouble building my project with Jenkins and referencing the Sherlock project library.
I can build the project with ant on my local system. The problem seems to be referencing the Sherlock library on the build server.
I pass an environment variable to ant with the relative path to the Sherlock library project:
android.library.reference.1=../../buildlibraries/androidlibraries/sherlock/library
I'm getting this error.
**BUILD FAILED**
/SDK/android-sdk-macosx/tools/ant/build.xml:595:
The following error occurred while executing this line:
/SDK/android-sdk-macosx/tools/ant/build.xml:571:
../../buildlibraries/androidlibraries/sherlock/library resolve to a path with
no project.properties file for project /Users/Jenkins/buildlibraries/androidlibraries/sherlock/library
I checked and a project.properties file does exist at that location.
It has these properties:
android.library=true
# Project target.
target=android-14
I had the same thing happen to me just now. I use both a Windows and Mac to develop with. I watne d to test my project on both platforms. It built just fine on my Windows machine, but broke on my Mac. When I looked at my project.properties in my Android application (not library projects) on the Mac, I saw that my library projects were referenced this way:
android.library.reference.1=LibraryProjects\\my_lib_project
I changed it to the line below, and it worked just fine!
android.library.reference.1=LibraryProjects/my_lib_project
I solved the issue by editing and checking in the project.properties file with the same property: android.library.reference.1=../../buildlibraries/androidlibraries/sherlock/library
I'm not sure why it works. Why would ant care if the property is passed in by Jenkins vs. declared in the project's property file?
Now I have two paths in my project.properties file: one for a local build and one for the build on Jenkins.
I had similar issue with error ../google-play-services_lib resolve to a path with no project.properties file for project. It has to work in Jenkins CI (Cloudbees), so no manual project.properties editing.
My solution was to replace android update lib-project --path ... with ugly but working echo "android.library.reference.1=../../../..$ANDROID_HOME/extras/google/google_play_services/libproject/google-play-services_lib" >> project.properties in Jenkins shell command.
I had this problem because I hadn't downloaded the google play services package using the android tool. When I checked my android sdk directory ($ANDROID_HOME) there was no "$ANDROID_HOME/extras/google" folder.
I fixed this by running android and downloading "Google Play services" found in the extras section.

Building Android library with Eclipse vs Ant

I have a simple Android library project, which contains network calls functionality only. It doesn't need to inherit any XML/resources etc… to calling application. When I build this project using Eclipse IDE (right click on project and click on Build Project), it generates a JAR under bin/libproject.jar. I can simply drop this file to any project's build path and it works fine.
Now, I want to implement continuous integration for my library. That means, I need some command-line way to achieve the same (building jar, when I build the project using ant). Ant builds the project differently. It creates classes.jar in bin/ folder, which is not the same as as libproject.jar.
I believe Eclipse's Build Project (ADT rev-21) is doing something magical to build this complete JAR for my library project (this is more like a java project like JAR).
Do you know how can I achieve the same using command line?
im using eclipse 4.3 w/ ant and with sdk tools 21.1
IMO - they recently changed the sdk regarding lib dependencies.
http://tools.android.com/recent/dealingwithdependenciesinandroidprojects
see the above link.
my example lib dependency(transitive) as follows:
ABS <== SlidingMenu <== MyProject
so, in SM.project.properties...
android.library.reference.1=../../src/ABS/library
and, in MP.project.properties ...
android.library.reference.1=../../src/SlidingMenu/library
The ant build, run on proj=SM using either eclipse internal, ant build tools OR ant on CLI in a terminal session outside eclipse
does following:
[javac] Note: Recompile with -Xlint:deprecation for details.
[echo] Creating library output jar file...
[jar] Building jar: /home/rob/src/tools/ActionBarSherlock-4.2.0/library/bin/classes.jar
and ant build, run on proj=MP does the following:
Setting project property: out.library.jar.file -> /home/rob/src/SlidingMenu/library/bin/classes.jar
..
[jar] Building jar: /home/rob/src/SlidingMenu/library/bin/classes.jar
IMO - you should focus on 2 things :
get the lib reference correct in the file=project.properties of the dependent.
double check in eclipse the project /properties/ java build path / order and export
read the link as it contains multiple , specific NOTEs relating to 'order export'...
When you build the dependent project in ant , it should trigger internally, builds of the other projects. I think that is controlled in the build path of the dependent project.
An additional NOTE on debugging - i could not debug directly from the project explorer because the launcher did not like the "classes.jar" for the 2 , dependent projects. Debug insisted on there being jars with names "${project-name}.jar" in the ./bin directory of each library. But ant assigns "classes.jar" as shown above.
So, to debug, i used the alternate method of DDMS tab in eclipse w/ the app already running. then u find the process and attach the debugger.

Ant Build Android Project With Dependencies

I'm trying to build an app (let's call it android-app) with a dependency on an SDK (let's call it sdk) via Ant. Eclipse is not installed on this computer (for reasoning, it's a CI box with Jenkins).
Both projects are in two completely separate directories side by side. android-app is in the directory ~/.jenkins/jobs/android-app/workspace and sdk is in the directory ~/.jenkins/jobs/sdk/workspace.
Let's assume both projects are "vanilla" and have not been built with Ant before. I cd to the ../android-app/workspace directory and run android update project -p . --library ~/.jenkins/jobs/sdk/workspace which passes. I then cd to the ../sdk/workspace directory and run android update project -p . which also passes.
At this point I cd back to the ../android-app/workspace directory and run ant clean build. It fails with the error:
BUILD FAILED
/path/to/ant/build.xml:440:
/path/to/sdk/workspace resolve to a path with no project.properties file for
project /path/to/android-app/workspace
... where /path/to is the full path to the directories. I simplified it here.
If I cd to the sdk workspace and open project.properties, I receive the following:
# ProGuard
proguard.config=proguard.cfg
# Project target.
target=android-10
android.library=true
It does exist. So do all of these files:
So, why is this failing? What am I doing wrong? I tried to provide as many details as possible. Please let me know if I can provide anything additional.
Well, I encounter this problem too.
I use strace to find out what the hell is going on and found that the path you specified in project.properties will be appended with your current folder path as its prefix.
For example,
/home/myfolder/project > ant debug
And the library you specified in project.properties is /path/to/library
Then, the path will become
/home/myfolder/project/path/to/library
Just to fill in the answer gap here, my Java version was completely off. I'm super embarrassed.

Categories

Resources