【问题标题】:Ant build script: cannot find android.jarAnt 构建脚本:找不到 android.jar
【发布时间】:2012-02-16 23:25:09
【问题描述】:

你好,

我无法使用 ant 构建脚本编译我的项目。错误信息:

Ant cannot find symbol...

我阅读了有关创建 build.xml 的信息,但似乎还不够。我的项目目录布局如下:

项目

    • ...

libarie_with_needed_java.file

    • 客户
    • 帮手

如何使用外部参考? Ant 找不到 android jarbuild.xml 文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
==================================================================== -->
<project name="test" default="main" basedir=".">

<!-- ==================================================================== 
      Declare global properties for reuse and control of script
     ==================================================================== -->

<!-- For project source files  -->
<property name="src.dir" location = "src/de/test"/> 
<property name="common.link" location = "../test-common/common"/> 
<!-- For compiled/output files. -->
<property name="build.dir" location = "build/source"/>
<!-- For class libraries and dependency files. -->
<property name="lib.dir" location = "lib"/>
<property name="sdk.dir" location = "../android-sdk-windows/" />    

<!-- ==================================================================== 
      Einstiegspunnkt - Target main
     ==================================================================== -->
<target name="main" depends="compile"  description="getting started">
  <echo message="start main target"/>   
</target>

<!-- ==================================================================== 
      Übersetzen - Target compile
     ==================================================================== -->
<target name="compile" depends="init">
  <echo message="start compile target"/>

  <javac srcdir="${src.dir}" destdir="${build}" debug="on"/>
  <classpath refid="classpath"/> 
</target>

<!-- ==================================================================== 
      Initialisierungen - Target init
     ==================================================================== -->
<target name="init" description="create needed directories">
  <echo message="start init target"/>
  <mkdir dir="${build}"/>
</target>   

</project>

我使用来自网站的示例和 Eclipse 生成的文件创建了这个文件。

我已删除以下外部属性文件(以简化问题):

<property file="local.properties" />
<property file="build.properties" />
<property file="default.properties" />          

我需要包含来自不同 src 位置的外部 .java 文件。

我需要知道如何复制项目中的外部文件并将所有内容编译在一起。

谢谢, 马塞尔

【问题讨论】:

    标签: android ant build


    【解决方案1】:

    属性文件通常包含在整个主构建脚本中使用的变量的值。

    要找出找不到 android.jar 的原因,请执行以下操作:

    1. 浏览到包含build.xml的目录。
    2. 向上浏览一个目录 (../)。
    3. 向下浏览到android-sdk-windows/platforms/android-4/
    4. 确保android.jar 在该目录中。

    否则,您将不得不更改 android.jar 位置的路径,相对于 build.xml 文件。

    【讨论】:

    • 是的,它在里面,我想我在 build.xml 中做了错误的思考
    • @marcel:使用 Ant 的 echo 任务 (ant.apache.org/manual/Tasks/echo.html) 显示脚本中变量的值。由于某种原因,JAR 文件没有进入类路径。
    • 感谢您的回复。我想我在 build.xml 中包含了 sdk false 或将其描述为 false!请问你能告诉我怎么做吗?马塞尔
    • @marcel:我建议您阅读有关 Ant 任务的更多信息并熟悉它们的工作方式。另外,请看这里:stackoverflow.com/questions/722774/…
    【解决方案2】:

    您使用 SDK 的位置定义了一个名为 sdk.dir 的属性,但您不会在 build.xml 文件的其他任何地方使用它。

    尝试在 build.xml 文件中添加它

    <path id = "classpath">
        <fileset dir = "${lib.dir}" includes = "*.jar"/>
        <fileset dir = "${sdk.dir}" includes = "*.jar"/>
    </path>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-01
      • 2010-11-12
      • 2011-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-17
      • 1970-01-01
      相关资源
      最近更新 更多