我有一个主构建文件,我用它来构建一系列Android项目.每个Android项目都引用相同的Android库项目(我称之为CoreLibrary).以下是我的子任务.
<target name="build" description="Builds (only) all applications">
<subant>
<target name="debug" />
<fileset refid="all-applications" />
</subant>
</target>
问题:我可以做些什么来防止在我的子任务的所有应用程序文件集中为每个Android项目重建CoreLibrary?这将大大加快我的构建时间,所以我希望我能做些什么.
解决方法:
实际上,我刚刚想出了解决这个问题的方法.基本思想是,我的ANT文件找到所有库项目,首先构建它们,然后使用nodeps目标构建我的项目的其余部分.这有效地防止了CoreLibrary不断重新编译的情况.
<?xml version="1.0" encoding="UTF-8"?>
<project name="MasterBuild">
<!-- A property for the name of the file that contains 'android.library=true' (which is how we find library projects) -->
<property name="library.setting.file.name" value="project.properties" />
<filelist id="normal-projects" dir=".">
<!-- You want to add your own projects here -->
<file name="./MyProject/build.xml" />
<file name="./MyProject2/build.xml" />
<file name="./MyProject3/build.xml" />
</filelist>
<fileset id="all-libraries-properties" dir=".">
<include name="*/${library.setting.file.name}" />
<contains casesensitive="true" text="android.library=true" />
</fileset>
<pathconvert property="all-libraries" refid="all-libraries-properties">
<globmapper from="*${library.setting.file.name}" to="*build.xml" />
</pathconvert>
<target name="-set-debug-mode">
<property name="build.target" value="debug" />
<property name="install.target" value="installd" />
</target>
<target name="-set-release-mode">
<property name="build.target" value="release" />
<property name="install.target" value="installr" />
</target>
<target name="-build-dependencies" unless="built.dependencies">
<property name="built.dependencies" value="true" />
<subant buildpath="${all-libraries}" target="${build.target}" inheritall="false" />
</target>
<target name="-build-normal-projects" depends="-build-dependencies">
<subant inheritall="false">
<target name="nodeps" />
<target name="${build.target}" />
<resources refid="normal-projects" />
</subant>
</target>
<target name="-install-normal-projects">
<subant inheritall="false">
<target name="${install.target}" />
<resources refid="normal-projects" />
</subant>
</target>
<target name="debug" depends="-set-debug-mode, -build-normal-projects" description="Builds (only) a debug-key signed application" />
<target name="release" depends="-set-release-mode, -build-normal-projects" description="Builds (only) a release-key signed application" />
<target name="installd" depends="-set-debug-mode, -install-normal-projects" description="Installs (only) a debug-key signed application" />
<target name="installr" depends="-set-release-mode, -install-normal-projects" description="Installs (only) a release-key signed application" />
</project>
注意如果我编写了一个实际找到库依赖顺序的任务,那么可以改进此解决方案,以便我可以使用nodeps目标构建库.此外,可能有一种方法可以自动检测“正常项目”,但我还没有需要.最后,我从普通的ANT文件中展开了很多东西,把它带到这里,所以希望我没有错过任何东西.然而,这个概念存在.