uiautomator开发使用到第三方jar,出现class not found或者 BUILD FAILED的问题

在基于uiautomator进行安卓遍历测试的二次开发中,使用第三方jar如xStream时,可能会遇到编译失败或运行时找不到类的错误。错误主要由两个原因引起:1) 编译时未添加jar包;2) jar包已添加但class文件路径未正确放入classes.dex。解决方法是编辑uiBuild.xml文件,将jar包路径添加到编译和dex目标中,确保编译和打包过程包含所有必要的依赖。
摘要由CSDN通过智能技术生成

最近做安卓的遍历测试,是基于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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值