简体   繁体   English

Espresso 2升级后测试失败(失败:由于'java.lang.IllegalAccessError'导致仪器运行失败)

[英]Tests fail after Espresso 2 upgrade (failed: Instrumentation run failed due to 'java.lang.IllegalAccessError')

After upgrading Espresso to version 2 none of my unit tests will run on pre-lollipop devices. 将Espresso升级到版本2后,我的单元测试都不会在棒棒糖前设备上运行。 See the trace below: 见下面的曲目:

15:07:07.627 [WARN] [org.gradle.api.Project] Tests on Samsung Galaxy S3 - 4.3 - API 18 - 720x1280 - 4.3 failed: Instrumentation run failed due to 'java.lang.IllegalAccessError'
15:07:07.832 [WARN] [org.gradle.api.Project] 
com.android.builder.testing.ConnectedDevice > hasTests[Samsung Galaxy S3 - 4.3 - API 18 - 720x1280 - 4.3] FAILED 
15:07:07.832 [WARN] [org.gradle.api.Project] No tests found.
15:07:07.834 [DEBUG] [org.gradle.api.Project] DeviceConnector 'Samsung Galaxy S3 - 4.3 - API 18 - 720x1280 - 4.3': uninstalling com.nordstrom.fla.test
15:07:08.252 [DEBUG] [org.gradle.api.Project] DeviceConnector 'Samsung Galaxy S3 - 4.3 - API 18 - 720x1280 - 4.3': uninstalling com.nordstrom.fla
15:07:08.666 [INFO] [org.gradle.api.Project] deleteDir(/Users/graemeharnish/workspace/fla-android/app/build/outputs/reports/androidTests/connected) returned: true
15:07:08.702 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':app:connectedAndroidTest'
15:07:08.702 [LIFECYCLE] [class org.gradle.TaskExecutionLogger] :app:connectedAndroidTest FAILED

The stack trace is equally unhelpful 堆栈跟踪同样无益

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:connectedAndroidTest'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:305)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:88)

My gradle dependencies 我的gradle依赖

dependencies {
apt "org.robobinding:codegen:$robobindingVersion"
compile "org.robobinding:robobinding:$robobindingVersion:with-aop"
aspectPath("org.robobinding:robobinding:$robobindingVersion:with-aop")

compile 'org.lucasr.twowayview:twowayview:0.1.4'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.3'
provided 'com.android.support:appcompat-v7:21.0.3'
compile 'net.hockeyapp.android:HockeySDK:3.5.0-b.4'
compile 'me.dm7.barcodescanner:zbar:1.5'
compile 'com.squareup.picasso:picasso:2.4.0'
compile 'com.squareup:otto:1.3.5'

compile 'org.apache.commons:commons-lang3:3.0'

compile 'com.nispok:snackbar:2.8.0'

compile 'com.rengwuxian.materialedittext:library:1.8.0'
compile 'com.crittercism:crittercism-android-agent:+'

provided 'org.roboguice:roboblender:3.+'

compile 'com.android.support:cardview-v7:21.0.+'
compile 'com.melnykov:floatingactionbutton:1.1.0'

compile 'com.google.code.findbugs:jsr305:1.3.9'
compile 'com.android.support:support-annotations:21.0.3'

androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.0'

androidTestCompile('org.mockito:mockito-core:1.9.5',
        'com.google.dexmaker:dexmaker-mockito:1.1',
        'com.google.dexmaker:dexmaker:1.1')

} }

What's strange is it work on 5.0 devices no problem. 有什么奇怪的是它在5.0设备上工作没问题。

Older devices have problems running tests when you have the same dependency in your app and test app that instruments the app. 当您在应用程序和测试应用程序中具有相同的依赖关系时,较旧的设备在运行测试时会出现问题。

To work around this issue, you will have to figure out which dependencies cause the problem. 要解决此问题,您必须确定哪些依赖项会导致问题。

In my case it was both Dagger and Espresso depending on javax.inject and this is how it can be "fixed": 在我的情况下,根据javax.inject ,它是Dagger和Espresso,这就是它如何“修复”:

androidTestCompile('com.android.support.test.espresso:espresso-core:2.0') {
    exclude group: 'javax.inject'
}

If you include more or weirder dependencies, you may have a look at this build.gradle . 如果包含更多或更奇怪的依赖项,您可以查看此build.gradle

When using espresso-contrib, you may need to do this: 使用espresso-contrib时,您可能需要这样做:

androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.0') {
    exclude group: 'javax.inject'
    exclude group: 'com.android.support'
}

The problem usually happens when the same dependencies are included more than once or with different versions. 当相同的依赖项被包含多次或使用不同的版本时,通常会发生此问题。

I have a working project using espresso2 with multidex for api level 14+. 我有一个工作项目使用espresso2和multidex for api level 14+。

Check this SO question . 检查这个问题 The accepted answer helped a lot. 接受的答案帮了很多忙。

Mostly, using the ./gradlew -q :myproject:dependencies you can check for duplicate dependencies or the same dependency with different versions included more than once. 大多数情况下,使用./gradlew -q:myproject:dependencies,您可以检查重复的依赖关系或不同版本包含的相同依赖关系不止一次。

This is an example of my espresso dependencies, but I had to change and exclude many: 这是我的espresso依赖项的一个例子,但我不得不改变并排除许多:

....
//Espresso 2
androidTestCompile('com.android.support.test.espresso:espresso-core:2.0') { 
    exclude group: 'com.google.guava'
    exclude module: 'espresso-idling-resource'
}
androidTestCompile('com.android.support.test:testing-support-lib:0.1') { 
    exclude group: 'com.google.guava'
    exclude module: 'espresso-idling-resource'
}
testingCompile ('com.android.support.test.espresso:espresso-contrib:2.0') {
    exclude group: 'com.google.guava'
    exclude group: 'com.android.support', module: 'support-v4'
}
// Need to exclude this when running test
androidTestCompile('com.android.support:multidex-instrumentation:1.0.1') {
    exclude group: 'com.android.support', module: 'multidex' 
}
....

The ./gradlew -q :myproject:dependencies will give you an output like the following for every variant+flavour combination: ./gradlew -q:myproject:dependencies将为每个变体+ flavor组合提供如下输出:

_prodTestingTestApk - ## Internal use, do not manually configure ##
+--- com.android.support.test.espresso:espresso-core:2.0
|    +--- com.squareup:javawriter:2.1.1
|    +--- org.hamcrest:hamcrest-integration:1.1
|    |    \--- org.hamcrest:hamcrest-core:1.1
|    +--- org.hamcrest:hamcrest-library:1.1
|    |    \--- org.hamcrest:hamcrest-core:1.1
|    +--- javax.inject:javax.inject:1
|    +--- com.android.support.test:testing-support-lib:0.1
|    |    \--- junit:junit-dep:4.10
|    |         \--- org.hamcrest:hamcrest-core:1.1
|    +--- com.google.code.findbugs:jsr305:2.0.1
|    +--- javax.annotation:javax.annotation-api:1.2
|    \--- org.hamcrest:hamcrest-core:1.1
+--- com.android.support.test:testing-support-lib:0.1 (*)
\--- com.android.support:multidex-instrumentation:1.0.1

I had similar problem when I was operating on RecyclerView in my tests which was solved by adding below code to build.gradle : 当我在我的测试中使用RecyclerView时遇到了类似的问题,这是通过在build.gradle添加以下代码来build.gradle

configurations {
    androidTestCompile.exclude group: 'com.android.support', module: 'recyclerview-v7'
}

And also you can try to add following exclude as well: 此外,您还可以尝试添加以下排除:

configurations {
    androidTestCompile.exclude group: 'com.android.support', module: 'support-v4'
} 

So, my configurations in build.gradle looking like that: 所以,我在build.gradle configurations看起来像这样:

configurations {
    androidTestCompile.exclude group: 'com.android.support', module: 'support-v4'
    androidTestCompile.exclude group: 'com.android.support', module: 'recyclerview-v7'
} 

This solved both of the issues I faced with: java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation and java.lang.NoClassDefFoundError . 这解决了我遇到的两个问题: java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementationjava.lang.NoClassDefFoundError After that I was able to run tests on pre-lollipop devices. 之后,我能够对棒棒糖前设备进行测试。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Lollipop下的设备在Espresso中测试失败(失败:由于“ java.lang.IllegalAccessError”,检测运行失败) - Tests fail in Espresso with devices under Lollipop (failed: Instrumentation run failed due to 'java.lang.IllegalAccessError') 由于'java.lang.IllegalAccessError',检测运行失败。 Gradle + Espresso - Instrumentation run failed due to 'java.lang.IllegalAccessError'. Gradle + Espresso Android Espresso UI测试-测试运行失败:由于“ java.lang.IllegalAccessError”,检测运行失败 - Android Espresso UI test - Test running failed: Instrumentation run failed due to 'java.lang.IllegalAccessError' 由于“java.lang.IllegalAccessError”,检测运行失败 - Instrumentation run failed due to 'java.lang.IllegalAccessError' 由于Robotium测试项目中带有“ Actionbar Sherlock”的“ java.lang.IllegalAccessError”,仪表运行失败 - Instrumentation run failed due to 'java.lang.IllegalAccessError' in Robotium test project with actionbar sherlock 通过Espresso运行单元测试时,由于“ java.lang.ClassNotFoundException”错误,导致仪表运行失败 - Instrumentation run failed due to 'java.lang.ClassNotFoundException'error while running Unit test through Espresso Espresso:由于“keyDispatchingTimedOut”,仪器运行失败 - Espresso: Instrumentation run failed due to 'keyDispatchingTimedOut' 由于'java.lang.IllegalArgumentException',如何纠正'Instrumentation运行失败' - how to correct a 'Instrumentation run failed due to 'java.lang.IllegalArgumentException'' 由于'java.lang.NullPointerException'导致Instrumentation运行失败 - Getting Instrumentation run failed due to 'java.lang.NullPointerException' 由于“ java.lang.NullPointerException”,检测运行失败 - Instrumentation run failed due to 'java.lang.NullPointerException'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM