最近做安卓的遍历测试,是基于uiautomator做的,二次开发,避免不了使用第三方jar,比如这边我使用到的就是xStream,但是在打包的过程中会出现
classNotFound或者是Build Failed的问题。
这里有两个原因:
1、编译的时候,没有把jar包添加进来,这时候的体现一般是报BUILD FAILED的错误。
2、jar包添加进来了,没有把jar下的class文件的路径对应放到classes.dex文件中,造成类无法找到,这时候一般会报classNotFound的错误。
针对以上两个问题,我们需要对应修改uiBuild.xml文件,这个文件是ant自带的,目录为${sdk.dir}/tools/ant/uibuild.xml
1、将jar包的路径,放到compile下,红色部分为新增内容,意思是将项目的libs文件夹下的所有jar包都加入编译。
<target name="compile" depends="-build-setup, -pre-compile">
<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}"
fork="${need.javac.fork}">
<src path="${source.absolute.dir}" />
<compilerarg line="${java.compilerargs}" />
<classpath>
<fileset dir="${jar.libs.dir}" includes="*.jar"/>
</classpath>
</javac>
</target>
2、把class的路径加入到classes.dex文件中,红色部分为新增内容。
<target name="-dex" depends="compile, -post-compile">
<dex executable="${dx}"
output="${intermediate.dex.file}"
nolocals="@{nolocals}"
verbose="${verbose}">
<fileset dir="${jar.libs.dir}" includes="*.jar"/>
<path path="${out.classes.absolute.dir}"/>
</dex>
</target>
最后修改后的uibuild.xml文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<project name="android_rules" default="debug">
<!-- This build file is imported by the project build file. It contains
all the targets and tasks necessary to build Android projects, be they regular
projects, library projects, or test projects. At the beginning of the file
is a list of properties that can be overridden by adding them to your ant.properties
(properties are immutable, so their fir