【问题标题】:"cannot find symbol" when compiling with Ant使用 Ant 编译时“找不到符号”
【发布时间】:2010-10-13 11:07:53
【问题描述】:

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

出于这个原因,我已经覆盖了那个目标:我已经从 ant_rules_r3.xml 复制了已编译的任务,并且我已经像这样更改了 javac 任务(请参阅 cmets 了解我所做的更改):

<!--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);

似乎它是用 JDK 1.5 而不是 1.6 编译的,即使我已将目标属性设置为 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。

我怎样才能让它正确编译?

【问题讨论】:

    标签: java android ant build-automation compilation


    【解决方案1】:

    由于您已指定引导类路径以使用 Android SDK 类,因此这些类可能包含 IOException 类,该类未实现具有 Throwable 第二个参数的双参数构造函数。该构造函数在 Java 6 中是新的,但根据 recent Android (2.2) docs,Android 版本只有 Java-1.5 样式的构造函数,并且没有实现两个采用 Throwable args 的新构造函数。

    在引入第二个项目之前,您没有提及您是否已成功构建此项目 - 所以我建议您检查本地 Android 启动类以查看 IOException 提供的构造函数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-16
      相关资源
      最近更新 更多