在这里回答:将外部 jars 添加到 Android UIautomator 项目
请使用 neeraj t 给出的 custom_rules.xml 文件(下面给出的编辑版本)。
neeraj t 的最后一个答案对我有用。我需要做的唯一更新是:将 jar 放入 libs 而不是“lib”文件夹并将 custom_rule.xml 命名为 custom_rules.xml 并将所有内容放入项目中,如下所示(我也发布了对原始解决方案的编辑)
<?xml version="1.0" encoding="UTF-8"?>
<project name="custom_rules">
<property name="jar.libs.dir" value="libs" />
<property name="jar.libs.absolute.dir" location="${jar.libs.dir}" />
<path id="classpath">
<fileset dir="${jar.libs.absolute.dir}">
<include name="your-helping-version.jar" />
<include name="gson-2.2.2.jar" />
</fileset>
</path>
<!-- version-tag: VERSION_TAG -->
<import file="${sdk.dir}/tools/ant/uibuild.xml" />
<!-- overwrite the compile target in uibuild.xml to include to external
jars -->
<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}" />
<classpath refid="classpath" />
<compilerarg line="${java.compilerargs}" />
</javac>
</target>
<!-- overwrite the -dex target in uibuild.xml to include external jar files
into the target dex file. -->
<target name="-dex" depends="compile, -post-compile">
<dex executable="${dx}" output="${intermediate.dex.file}"
nolocals="@{nolocals}" verbose="${verbose}">
<fileset dir="${jar.libs.absolute.dir}">
<include name="your-helping-version.jar" />
<include name="gson-2.2.2.jar" />
</fileset>
<path path="${out.classes.absolute.dir}" />
</dex>
</target>
</project>