I’m inching my way to doing an Ant build on my Eclipse sources. The ultimate objective is to have the Eclipse sources as the input and the output go into a folder entirely outside the Eclipse file structure.
It’s a while since I’ve used Ant, so I’m gradually commenting out, then uncommenting bits from the standard build.xml that gets generated when you build a sample project from the command line. I’m going to put lots of ‘echos’ in to make sure it gets the directories right before I let it actually DO something. I started off with a simple junk target at the top of the build.xml that just echoed ‘junk’ – this worked OK.
I then uncommented this bit :
<!-- Custom Android task to deal with the project target, and import the
proper rules.
This requires ant 1.6.0 or above. -->
<path id="android.antlibs">
<pathelement path="${sdk.dir}/tools/lib/anttasks.jar" />
<pathelement path="${sdk.dir}/tools/lib/sdklib.jar" />
<pathelement path="${sdk.dir}/tools/lib/androidprefs.jar" />
</path>
<taskdef name="setup"
classname="com.android.ant.SetupTask"
classpathref="android.antlibs" />
<!-- Lots of commented out stuff -->
<setup />
Once I let this run, then the echo I did have disappears and I get the following output
[setup] Android SDK Tools Revision 7
[setup] Project Target: Google APIs
[setup] Vendor: Google Inc.
[setup] Platform Version: 2.1-update1
[setup] API level: 7
[setup]
[setup] ------------------
[setup] Resolving library dependencies:
[setup] ------------------
[setup] Ordered libraries:
[setup] ------------------
[setup]
I’m expecting it to fail of course, because I haven’t set up any input/output/lib directories in the .properties files. I am curious to know why the taskdef itself runs when I only invoke the ‘junk’ target. I’d also like to know what the SetupTask and all the others in the anttasks.jar actually do and where I can find some documentation for them.
Any task that is included at the top level of a build file (i.e. outside of any target) is automatically included in an implicit initialisation target that gets run whenever the build is run, whatever actual target you specify.
So the
taskdefelement for the setup task declares this task, but then the next line,<setup />, because it is the top level of the build file, will cause the task to be executed everytime you run ant on this build file.