简体   繁体   English

为Gradle设置Deckard。 Robolectric测试出错

[英]Setup Deckard for Gradle. Error with Robolectric test

I'm trying to create a project with Robolectric deckard-gradle Everything is ok but when I run a robolectric test the build failed with an exception: 我正在尝试使用Robolectric deckard-gradle创建一个项目一切正常但是当我运行robolectric测试时,构建失败并出现异常:

cd my-project
./gradlew clean test

1 test completed, failed
:testDebug FAILED

java.lang.IllegalArgumentException
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.robolectric.bytecode.AsmInstrumentingClassLoader.findClass(AsmInstrumentingClassLoader.java:140)
at org.robolectric.bytecode.AsmInstrumentingClassLoader.loadClass(AsmInstrumentingClassLoader.java:98)
at org.robolectric.SdkEnvironment.bootstrappedClass(SdkEnvironment.java:45)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:205)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:86)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:49)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:103)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:355)
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:744)

On the other hand, when run a Espresso test any error doesn't occurs 另一方面,当运行Espresso测试时,不会发生任何错误

Environment: 环境:

Gradle 1.10 Gradle 1.10

JDK 8 JDK 8

Last update of Android SDK Android SDK的上次更新

Thanks! 谢谢!

I also ran into this issue, I'll leave an answer here in case it helps anyone else that runs across this post when searching for this error. 我也遇到了这个问题,我将在这里留下一个答案,以防它在搜索此错误时帮助其他人遇到这篇文章。 For me, it was that the version of Robolectric (or more specifically, the version of ASM it relies on) didn't work with Java 8. Upgrading from Robolectric 2.2 to 2.3 fixed this for me. 对我来说,Robolectric的版本(或更具体地说,它依赖的ASM版本)不适用于Java 8.从Robolectric 2.2升级到2.3为我解决了这个问题。

Solved. 解决了。 The error was caused by a version conflict in the .gradle folder (gradle-1.10 vs gradle 1.11). 该错误是由.gradle文件夹中的版本冲突引起的(gradle-1.10 vs gradle 1.11)。 Deleting the .gradle folder and regenerating gradle fixes the problem. 删除.gradle文件夹并重新生成gradle可以解决问题。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM