问题
I am currently developing a Java project in order to perform automatic screenshots of my Android application, however, when performing the uiautomator command:
adb shell uiautomator runtest AutoScreenshot.jar -c test.ScreenshotRoutine
I am getting the following error:
INSTRUMENTATION_RESULT: shortMsg=java.lang.RuntimeException
INSTRUMENTATION_RESULT: longMsg=Didn't find class "test.ScreenshotRoutine" on pa
th: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file
"/system/framework/uiautomator.jar", zip file "/data/local/tmp/AutoSc
reenshot.jar"],nativeLibraryDirectories=[/system/lib]]
INSTRUMENTATION_CODE: 0
I have already searched everywhere and lost around 1 day around this issue. It seems that the answers around these kind of questions are over 1 year old and none of the solutions have worked for me. I have followed the examples found here and here, and changed the project slightly and have the following project structure:
src
|- test
|- <class extending UiAutomatorTestCase>
|- interfaces
|- routines
|- utils
My ANT file for generating the JAR file is the following:
<?xml version="1.0" encoding="UTF-8"?>
<project name="AutoScreenshot.makejar" basedir=".">
<property name="src.dir" value="src"/>
<property name="libs.dir" value="libs"/>
<property name="root.dir" value="build"/>
<property name="jar.dir" value="${root.dir}/jar"/>
<property name="jar.file" value="${jar.dir}/AutoScreenshot.jar"/>
<property name="classes.dir" value="${root.dir}/classes"/>
<path id="jars-classpath">
<fileset dir="${libs.dir}">
<include name="*.jar"/>
</fileset>
</path>
<target name="clean">
<delete dir="${root.dir}"/>
</target>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<mkdir dir="${jar.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}" target="1.8" includeantruntime="false">
<classpath refid="jars-classpath"/>
</javac>
<jar jarfile="${jar.file}" basedir="${classes.dir}">
<fileset dir="${libs.dir}" includes="**/*.jar" />
<fileset dir="${classes.dir}" includes="**/*.class" />
</jar>
</target>
</project>
Inside my Java project, I have created a ´libs´ folder which holds:
- android.jar;
- junit.jar;
- uiautomator.jar.
Am I missing something, where am I missing it? If you need any other file you consider relevant, please feel free to ask.
UPDATE #1 - Add batch file content
Here is what I have in the batch file I've done in order to compile and upload the jar file
@echo off
echo CLEANING PROJECT
call ant clean
echo COMPILING JAR FILE
call ant compile
echo PUSHING JAR FILE TO DEVICE
call adb push "D:\Workspaces\...\build\jar\AutoScreenshot.jar" /data/local/tmp/
echo EXECUTING JAR FILE ON DEVICE
call adb shell uiautomator runtest /data/local/tmp/AutoScreenshot.jar -c test.ScreenshotRoutine#runRoutine -e lang en
Many thanks in advance.
来源:https://stackoverflow.com/questions/32200292/uiautomator-didnt-find-class-class-on-path-dexpathlist