I created a test project to understand how to build and run the tests using command line tool. I managed to create a project, updated it with
android update project -p .
and debug with
ant debug
When I added a library project to this test project, the ant debug started to fail because it couldn't find the build.xml of the library. The only solution I found atm is to update the library project as well (found here). Is this the correct way? I see pom.xml files in many of the libraries that I use. I know it is used by Maven (although I know nothing about it) and it might help me with another solution.
Ant is the official way to build android apk. Maven is an alternative way of doing it (not officially supported, but it works very well).
There are few differences regarding default project layout when working with maven or ant, but it's possible to have both build system working on the same source code if you do some additionnal configuration work (i.e. some information will be duplicated).
Default project layout with maven
- java source files are under `/src/main/java``
- dependencies are defined in the pom.xml (using the maven way of defining dependencies, with type
apklib
for android libraries)
Default project layout with ant (and eclipse ADT plugin)
- java source files are under
/src
- dependencies are defined in
/project.properties
and are specified using relative path.
Here is an example of project.properties
(it's a typical example of a library project referencing 2 other library project):
target=android-15
android.library=true
android.library.reference.1=../somelib
android.library.reference.2=../someOtherLib
(as you can see some additionnal information are stored in this file : the android target and the fact that the project is an library or an app. When you use maven, this information is in the pom.xml)
How to build a maven android lib with ant ?
The problems (when you need to build a maven-layout-android-library
with ant
) are the following:
- having a proper
/build.xml
(it can be done through android update library-project ...
here is the official doc about this command)
- having a proper
/project.properties
(it is partially done by the android update ...
command, but you may need to add some android.library.reference
by hand or with eclipse ADT plugin)
- telling
ant
that the java source files aren't at the default location, but are under /src/main/java
For this last point, here is how to do it:
(Important : it is not always required because sometimes the java source files are already under /src
in the maven-layout-project and in this case, the pom.xml contains the information that the source dir is /src
)
And that's all. Now, your maven-layout-android-library
can be build with ant debug