我最终搞清楚了这一点。我最终做的是使用Eclipse导出工具为三个Java库项目导出一个ant构建脚本。然后我创建了一个名为build-custom.xml的文件,其中包含用于复制罐子的其他目标。
接下来,我在Android库项目上使用了android update lib-project命令来生成该项目的build.xml(如http://developer.android.com/tools/projects/projects-cmdline.html中所述)。为了在构建中包含Java库项目,您必须将它们复制到Android项目的libs文件夹中。所以我在Android库项目中创建了一个名为custom_rules.xml的构建文件,它将jar文件复制到lib文件夹中。重要提示:另外编写一个规则,在完成时删除jar,否则当您尝试在Eclipse中运行时会得到Davlik Error 1。
您可能有也可能没有Android库项目,但其步骤与库项目的主要项目几乎相同。只需使用android update project命令,然后创建一个custom_rules.xml来复制相应的jar。
编辑:
我使用Eclipse来生成基本的Java库项目构建脚本后,我创建了一个common.xml Ant构建文件。这个文件基本上是这样的:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project name="common">
<target name="clean">
<delete dir="build/libs" />
<ant antfile="build.xml" dir="./SubJavaLibrary/SampleSubLibrary1" target="clean" />
<ant antfile="build.xml" dir="./SubJavaLibrary/SampleSubLibrary1" target="cleanup-jars" />
<ant antfile="build.xml" dir="./SubJavaLibrary/SampleSubLibrary2" target="clean" />
<ant antfile="build.xml" dir="./SubJavaLibrary/SampleSubLibrary2" target="cleanup-jars" />
<ant antfile="build.xml" dir="./SubJavaLibrary/SampleSubLibrary3" target="clean" />
<ant antfile="build.xml" dir="./SubJavaLibrary/SampleSubLibrary3" target="cleanup-jars" />
<ant antfile="build.xml" dir="./AndroidSubProject" target="clean" />
</target>
<target name="samplesublibrary1">
<ant antfile="build.xml" dir="./SubJavaLibrary/SampleSubLibrary1" target="all" />
</target>
<target name="samplesublibrary2">
<ant antfile="build.xml" dir="./SubJavaLibrary/SampleSubLibrary2" target="all" />
</target>
<target name="samplesublibrary3" depends="samplesublibrary2">
<ant antfile="build.xml" dir="./SubJavaLibrary/SampleSubLibrary3" target="all" />
</target>
<target name="android-sub-project-copy-jars" depends="samplesublibrary1, samplesublibrary2, samplesublibrary3">
<ant antfile="build.xml" dir="./AndroidSubProject" target="android-project-copy-jars" />
</target>
<target name="android-sub-project-debug" depends="android-project-copy-jars">
<ant antfile="build.xml" dir="./AndroidSubProject" target="debug" />
</target>
<target name="android-sub-project-release" depends="android-project-copy-jars">
<ant antfile="build.xml" dir="./AndroidSubProject" target="release" />
</target>
<target name="android-sub-project-remove-jars">
<ant antfile="build.xml" dir="./AndroidSubProject" target="android-project-remove-jars" />
</target>
</project>
然后在Android的子项目,我添加了包含以下内容的custom_rules.xml文件:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse.ant.import?>
<project default="android-project-copy-jars" name="Copy required jars to lib folder">
<target name="android-project-copy-jars">
<copy file="../../build/libs/SampleSubLibrary1.jar" todir="libs"/>
<copy file="../../build/libs/SampleSubLibrary2.jar" todir="libs"/>
<copy file="../../build/libs/SampleSubLibrary3.jar" todir="libs"/>
</target>
<target name="android-project-remove-jars">
<delete file="./libs/SampleSubLibrary1.jar" />
<delete file="./libs/SampleSubLibrary2.jar" />
<delete file="./libs/SampleSubLibrary3.jar" />
</target>
</project>
然后我创建了一个主要的build.xml在包含并运行所有其他子build.xml文件的项目根目录中:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="all">
<target name="debug" depends="clean, main-debug, android-project-remove-jars" />
<target name="release" depends="clean, main-release, android-project-remove-jars" />
<import file="common.xml" />
<target name="clean" depends="common.clean">
<ant antfile="build.xml" dir="./Main" target="clean" />
</target>
<target name="main-debug" depends="android-sub-project-debug">
<ant antfile="build.xml" dir="./Main" target="debug" />
<copy file="./Main/bin/main-debug.apk" todir="./build/bin" />
</target>
<target name="main-release" depends="android-sub-project-release">
<ant antfile="build.xml" dir="./Main" target="release" />
<copy file="./Main/bin/main-release-unsigned.apk" todir="./build/bin" />
</target>
</project>
希望这有助于!
你有可能分享这些自定义文件的内容(或者至少是你添加到ant的规则)吗? – pjv
@pjv我添加了一些示例文件,希望能指出您正确的方向。 – rplankenhorn