运行espresso测试时遇到此错误,完整日志为:
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/junit/runner/notification/RunListener;
at android.support.test.internal.runner.RunnerArgs$Builder.fromBundle(RunnerArgs.java:150)
at android.support.test.runner.AndroidJUnitRunner.parseRunnerArgs(AndroidJUnitRunner.java:224)
at android.support.test.runner.AndroidJUnitRunner.onCreate(AndroidJUnitRunner.java:199)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4698)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.junit.runner.notification.RunListener" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/ro.adr.test.test-1/base.apk", zip file "/data/app/ro.adr.test-1/base.apk"],nativeLibraryDirectories=[/data/app/ro.adr.test.test-1/lib/x86, /data/app/ro.adr.test-1/lib/x86, /vendor/lib, /system/lib]]
我确信build.gradle和库项目build.gradle没有junit冲突,这是我的app / build.gradle
dependencies {
compile project(":adr")
compile fileTree(dir: 'libs', include: ['*.jar'])
// compile 'junit:junit:4.12'
compile 'org.hamcrest:hamcrest-core:1.3'
testCompile 'junit:junit:4.12'
String ver = "23.4.0"
compile "com.android.support:design:${ver}"
compile files("${System.env.HOME}/Dropbox/jvs/ro2/build/libs/ro2.jar")
androidTestCompile('com.android.support.test:runner:0.5')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2')
compile 'com.github.javafaker:javafaker:0.10'
}
答案 0 :(得分:1)
我找到解决方案,我检查上面的日志输出“/data/app/ro.adr.test.test-1/base.apk”,并用apktool
反编译,正常情况下,应该包括
base/smali/org/junit/runner/notification/RunListener.smali
但它不是,所以我认为最好的方法是:
<强>更新强>
上面的解决方案并不完美,如果你使用gradle,你可以:
gradle --daemon clean uninstallAll