As Android Java projects use Ant as a build tool, using Ivy for dependency management seems like a natural choice to me. However, while the basic setup works fine, I’m running into a strange issue. I’ve created a fork of an existing example on GitHub to easily reproduce the problem.
The point is, dependencies get downloaded into the “libs” directory just fine, but the build process as invoked by ant debug does not seem to find the JARs. However, it works fine if I call the “resolve” target not as part of my overloaded “-pre-build” target, but manually like in ant resolve debug.
I have verified that the libraries are really in “libs” just before “-pre-build” finishes (by listing the files in “libs” as part of the “-pre-build” target), so I’m really wondering why they cannot be found.
To reproduce, it’s important to delete the libraries from “libs” before running ant. Any ideas what’s going wrong here?
resolve:
[ivy:retrieve] :: Apache Ivy 2.3.0-rc1 - 20120416000235 :: http://ant.apache.org/ivy/ ::
[ivy:retrieve] :: loading settings :: file = /Users/seschube/development/IvyAndroidExample/ivysettings.xml
[ivy:retrieve] :: resolving dependencies :: com.example#ivy-android-example;0.1
[ivy:retrieve] confs: [default]
[ivy:retrieve] found org.acra#acra;4.2.3 in acra
[ivy:retrieve] found com.google.inject#guice;2.0-no_aop in maven2
[ivy:retrieve] found com.google.zxing.core#core;1.6 in zxing
[ivy:retrieve] :: resolution report :: resolve 115ms :: artifacts dl 5ms
---------------------------------------------------------------------
| | modules || artifacts |
| conf | number| search|dwnlded|evicted|| number|dwnlded|
---------------------------------------------------------------------
| default | 3 | 0 | 0 | 0 || 4 | 0 |
---------------------------------------------------------------------
[ivy:retrieve] :: retrieving :: com.example#ivy-android-example
[ivy:retrieve] confs: [default]
[ivy:retrieve] 4 artifacts copied, 0 already retrieved (1195kB/76ms)
-pre-build:
[echo] The "libs" directory contains: acra-4.2.3.jar;core-1.6.jar;guice-2.0-no_aop-javadoc.jar;guice-2.0-no_aop.jar
-code-gen:
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
[echo] Handling aidl files...
[aidl] No AIDL files to compile.
[echo] ----------
[echo] Handling RenderScript files...
[renderscript] No RenderScript files to compile.
[echo] ----------
[echo] Handling Resources...
[aapt] Generating resource IDs...
[echo] ----------
[echo] Handling BuildConfig class...
[buildconfig] Generating BuildConfig class.
-pre-compile:
-compile:
[javac] Compiling 3 source files to /Users/seschube/development/IvyAndroidExample/bin/classes
[javac] /Users/seschube/development/IvyAndroidExample/src/com/example/IvyAndroidExampleActivity.java:7: error: package org.acra does not exist
[javac] import org.acra.*;
[javac] ^
[javac] /Users/seschube/development/IvyAndroidExample/src/com/example/IvyAndroidExampleActivity.java:8: error: package com.google.inject does not exist
[javac] import com.google.inject.*;
[javac] ^
[javac] /Users/seschube/development/IvyAndroidExample/src/com/example/IvyAndroidExampleActivity.java:9: error: package com.google.zxing does not exist
[javac] import com.google.zxing.*;
[javac] ^
[javac] 3 errors
BUILD FAILED
I’ve found out what’s going on: The Android SDK’s build.xml adds all JARs from the
libsdirectory to theproject.all.jars.pathproperty as part of the-build-setuptarget. But this is too early if Ivy’sretrievetarget is called as part of-pre-build, because-build-setupis called before-pre-build. So-pre-build, although meant to be overridden, is the wrong place. As there seems to be no other “dummy” target meant to be overridden before-build-setupis called, I’m now overriding-build-setupin my build.xml file with a version that depends onretrieveand the original-build-setuplike this:<target name="-build-setup" depends="retrieve,android_rules.-build-setup" />.