我需要使用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。
如何才能正确编译此文件?