代码之家  ›  专栏  ›  技术社区  ›  Javi

用Ant编译时“找不到符号”

  •  2
  • Javi  · 技术社区  · 15 年前

    我需要使用Ant脚本生成一个apk文件,但是编译目标有问题。为了自动生成Ant脚本,我使用了Android工具和命令 android update project . 问题是这个项目依赖于另一个项目,所以我需要使用自定义编译任务。

    因此,我重写了该目标:我从 ant_rules_r3.xml 我已经改变了 javac 这样的任务(有关我更改的内容,请参阅注释):

    <!--I've changed the target 1.5 to target 1.6 -->
    <javac encoding="UTF8" target="1.6" debug="true" extdirs=""
          destdir="${out.classes.absolute.dir}"
          bootclasspathref="android.target.classpath"
          verbose="${verbose}"
          classpath="${extensible.classpath}"
          classpathref="android.libraries.jars">
        <src path="${source.absolute.dir}" />
        <!--My project has two src directories -->
        <src path="${source2.absolute.dir}" />
        <src path="${gen.absolute.dir}" />
        <src refid="android.libraries.src" />
        <!--I've added here the src dir of the other project -->    
        <src path="${dep1.source.absolute.dir}"/>
        <classpath>
            <!--I've added here the lib dir of the other project -->
            <fileset dir="${dep1.external.libs.absolute.dir}" includes="*.jar" />
            <fileset dir="${external.libs.absolute.dir}" includes="*.jar" />
            <fileset dir="${extensible.libs.classpath}" includes="*.jar" />
        </classpath>
    </javac>
    

    问题是当我使用 ant compile ,我得到以下错误:

    [javac].... cannot find symbol
    [javac] symbol  : constructor IOException(java.lang.String,java.security.NoSuchAlgorithmException)
    [javac] location: class java.io.IOException
    [javac]             throw new IOException("Algorithm not found", e);
    

    尽管我已经将target属性设置为1.6,但它似乎是用JDK1.5而不是1.6编译的。我的电脑使用的是Java版本1.6.0_20。

    我试过用 javac compiler="javac1.6" ,但我也有同样的错误。

    我也在 build.properties :

    ant.build.javac.target=1.6
    ant.build.javac.source=1.6
    

    但这也不能解决问题。将其设置为1.3而不是1.6会导致更多的错误,因此它似乎正在使用我在这里设置的JDK。

    如何才能正确编译此文件?

    1 回复  |  直到 11 年前
        1
  •  2
  •   martin clayton egrunin    15 年前

    因为您已经指定了bootclasspath来使用Android SDK类,所以这些类很可能包含IOException类,该类没有使用第二个参数来实现双参数构造函数。这个构造函数在Java6中是新的,但是根据 recent Android (2.2) docs ,Android版本只有Java-1.5风格的构造函数,并且

    在引入第二个项目之前,您没有提到是否已经成功构建了这个项目,所以我建议您检查本地的Android引导类,看看IOException提供了什么构造函数。

    推荐文章