我正在尝试添加Espresso来测试我们的应用程序。
当我没有inhamcrest-1.1.jar
时build.gradle
,我收到以下错误:
com.espresso.PracticeTest > testClickOnActionBar[Nexus 10 - 4.3] FAILED
java.lang.NoClassDefFoundError: org.hamcrest.Matchers
at com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId(ViewMatchers.java:274)
:Example:connectedInstrumentTest FAILED
当我确实有hamcrest-1.1.jar
in 时build.gradle
,我收到以下错误:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.cf.iface.ParseException: class name (org/hamcrest/beans/HasProperty) does not match path (hamcrest-library-1.1/org/hamcrest/beans/HasProperty.class)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:520)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
at com.android.dx.command.dexer.Main.processClass(Main.java:665)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
at com.android.dx.command.dexer.Main.access$600(Main.java:78)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:596)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
at com.android.dx.command.dexer.Main.run(Main.java:230)
at com.android.dx.command.dexer.Main.main(Main.java:199)
at com.android.dx.command.Main.main(Main.java:103)
...while parsing hamcrest-library-1.1/org/hamcrest/beans/HasProperty.class
这是build.gradle
dependencies {
instrumentTestCompile files('libs/dagger-1.1.0.jar', 'libs/dagger-compiler-1.1.0.jar',
'libs/hamcrest-library-1.1.jar',
'libs/espresso-1.0-SNAPSHOT.jar', 'libs/guava-14.0.1.jar', 'libs/javawriter-2.1.1.jar',
'libs/javax.annotation-api-1.2.jar','libs/javax.inject-1.jar',
'libs/jsr305-1.3.9.jar', 'libs/testrunner-1.0-SNAPSHOT.jar',
'libs/testrunner-runtime-1.0-SNAPSHOT.jar')
}
我做了一个./gradlew clean build
然后./gradlew example:connectedCheck
运行。
有没有人可以解决这个问题?