我正在使用Ant编译Android APK.APK将安装在具有jar文件的环境中(称为foo.jar).因此APK在编译期间需要了解foo.jar,但我不希望它包含在classes.dex中(因为它已经可用).
请注意,这不仅仅是将jar放在'libs'目录中.虽然这解决了问题的"编译"部分,但它没有解决将jar保留在classes.dex之外的问题.
在此先感谢您的帮助.
小智 6
-compile使用两条路径作为classpathref进行编译,但其中一条路径未在dexing中使用.
<target name="-compile" depends="-build-setup, -pre-build, -code-gen, -pre-compile">
<do-only-if-manifest-hasCode elseText="hasCode = false. Skipping...">
<!-- merge the project's own classpath and the tested project's classpath -->
<path id="project.javac.classpath">
<path refid="project.all.jars.path" />
<path refid="tested.project.classpath" />
</path>
<javac encoding="${java.encoding}"
source="${java.source}" target="${java.target}"
debug="true" extdirs="" includeantruntime="false"
destdir="${out.classes.absolute.dir}"
bootclasspathref="project.target.class.path"
verbose="${verbose}"
classpathref="project.javac.classpath"
fork="${need.javac.fork}">
<src path="${source.absolute.dir}" />
<src path="${gen.absolute.dir}" />
<compilerarg line="${java.compilerargs}" />
</javac>
…
</target>
Run Code Online (Sandbox Code Playgroud)
这些路径是"project.all.jars.path"和"tested.project.classpath",但路径"tested.project.classpath"在dexing中没有用,所以你可以在预编译目标中修改它,如下所示:
<target name="-pre-compile" >
<path id="tmp">
<pathelement path="${toString:tested.project.classpath}"/>
<fileset dir=“${exported.jars.dir}” >
<include name="*.jar" />
</fileset>
</path>
<path id="tested.project.classpath"><pathelement path="${toString:tmp}"/></path>
<path id="tmp"/>
</target>
Run Code Online (Sandbox Code Playgroud)
在这里,您在编译开始之前将导出的jar的路径附加到"tested.project.classpath".您可以将"exported.jars.dir"放在ant.properties文件中.
将 jar 放在其他目录(例如,foo/)并将其添加到编译类路径中怎么样?这样 JAR 就不会“导出”,因此 dex 工具不会对其进行操作。
| 归档时间: |
|
| 查看次数: |
2853 次 |
| 最近记录: |