Android的蚂蚁包含Java库项目 [英] Android Ant Include Java Library projects

查看:123
本文介绍了Android的蚂蚁包含Java库项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我想,这样它的工作原理与构建机器来编译工作使用Ant的Andr​​oid项目,我有问题。我有五个项目总:三都只是Java库项目,另外两个是真实的Andr​​oid项目。只有一个项目实际上是编译和安装,但它从其他项目拉来编译。

So I am trying to compile an Android project at work using Ant so that it works with a build machine and I am having issues. I have five projects total: three are just java library projects and the other two are actual Android projects. Only one project is actually compiled and installed but it pulls from the other projects in order to compile.

我使用Android的更新项目--name --target --path生成我的build.xml文件都试过了。它生成的build.xml就好了,但是当我去运行它,它不能正确包括我的其他项目的依赖关系。

I have tried using the "android update project --name --target --path " to generate my build.xml file. It generates the build.xml just fine but when I go to run it, it can't correctly include my other projects as dependencies.

我又试图导出使用Eclipse的build.xml文件,这将包括正确的依赖,但它不会生成我R.java文件。

I then tried to export the build.xml file using Eclipse and that will correctly include the dependencies but it won't generate my R.java files.

我会preFER第二种方法因为Eclipse已经采取了我的依赖设置的保健,而且是有什么我可以添加到build.xml文件中,将产生我的R.java文件正确?

I would prefer the second approach because Eclipse has already taken care of my dependency settings but is there something I can add to the build.xml file that will generate my R.java file correctly?

推荐答案

我最终搞清楚了这一点。我最后做的是使用Eclipse导出工具导出Ant构建脚本的三个Java库项目。然后,我创建了一个名为文件集结custom.xml其中包含额外的目标复制的罐子。

I ended up figuring this out. What I ended up doing is use the Eclipse export tool to export an ant build script for the three Java library projects. I then created a file called build-custom.xml which contains additional targets for copying the jars.

接下来,我用了Android的更新LIB项目的命令在Android库项目生成的build.xml为该项目(如在的 http://developer.android.com/tool​​s/projects/projects-cmdline.html )。为了包含在构建Java库项目时,必须将它们复制到libs文件夹中的Andr​​oid项目。所以,我创建了一个名为custom_rules.xml在Android库项目copys罐子到lib文件夹中生成文件。重要提示:同样写完成后,否则你将得到Davlik错误1,当你试图在Eclipse运行删除罐子规则

Next, I used the android update lib-project command on the Android library project to generate the build.xml for that project (as specified in http://developer.android.com/tools/projects/projects-cmdline.html). In order to include the Java library projects in the build, you have to copy them to the libs folder in the Android project. So I created a build file called custom_rules.xml in the Android library project that copys the jars into the lib folder. IMPORTANT: Also write a rule that removes the jars when done otherwise you will get Davlik Error 1 when you try and run in Eclipse.

您可能会或可能不会有一个Android库项目,但该步骤是pretty的大同小异为主营项目为库项目。只需使用Android的更新项目命令,然后创建一个custom_rules.xml复制适当的罐子。

You may or may not have an Android library project but the steps are pretty much the same for the main project as the library project. Just use the android update project command and then create a custom_rules.xml to copy the appropriate jars.

编辑:

在我使用了Eclipse生成构建脚本的基本Java库项目中,我创建了一个common.xml的Ant构建文件。这个文件基本上是这样的:

After I used Eclipse to generate the build scripts for the basic Java library projects, I created a common.xml ant build file. This file basically looks like this:

<?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文件如下:

Then in the Android-Sub-Project, I added a custom_rules.xml file that contained the following:

<?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文件:

I then created a main build.xml in the project root that includes and runs all the other sub build.xml files:

<?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>

希望这有助于!

Hope this helps!

这篇关于Android的蚂蚁包含Java库项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆