我试图编译使用Ant的Android项目,使之与构建机的工作原理,我有问题。 我有五个项目总:三都只是Java库项目,另外两个是实际的Android项目。 只有一个项目实际上是编译和安装,但它从其他项目拉动,以编译。
我已经使用了尝试android update project --name <name> --target <target> --path <path>
生成我的build.xml文件。 它生成的build.xml文件就好了,但是当我去运行它,它不能正确包括我的其他项目的依赖关系。
然后,我尝试导出使用Eclipse build.xml文件,将正确包括依赖,但它不会产生我的R.java文件。
我宁愿因为Eclipse已经采取的我的依赖设置护理第二种方法,但有什么我可以添加到build.xml文件,将正确生成我R.java文件?
我最终搞清楚了这一点。 我落得这样做是使用Eclipse导出工具导出Ant构建脚本三个Java库项目。 然后,我创建了一个名为集结custom.xml其中包含用于复制的罐子额外的目标。
接下来,我用在Android库项目在Android更新的lib项目命令生成该项目的build.xml文件(如在指定http://developer.android.com/tools/projects/projects-cmdline.html )。 为了包括构建Java库项目时,必须将它们复制到libs文件夹中的Android项目。 所以,我创建了一个名为custom_rules.xml在copys罐子到lib文件夹中的Android库项目的生成文件。 重要信息:另写一个规则做,否则你会得到Davlik错误1,当你尝试在Eclipse中运行时,去除罐子。
您可能会或可能不会有一个Android库项目,但步骤几乎为主营项目为库项目相同。 只要使用了Android更新项目命令,然后创建一个custom_rules.xml复制适当的罐子。
编辑:
我用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>
希望这可以帮助!