[英]Robolectric 4.0.2 test are not running in gradle 3.2.1 with NoSuchMethodError: setUseLegacyResources(Z)V
I have upgrade my Gradle plugin version from 2.3.3 to 3.2.1 and than my robolectric test start failing. 我已将Gradle插件版本从2.3.3升级到3.2.1,然后我的robolectric测试开始失败。 So i upgrade the robolectric version to 4.0.2 with given changes in Documentation . 所以我给出的变化升级robolectric版本4.0.2 文档 。
But still all my test are not able to execute with this error : 但是仍然我所有的测试都无法执行此错误:
java.lang.NoSuchMethodError: org.robolectric.RuntimeEnvironment.setUseLegacyResources(Z)V
at org.robolectric.android.internal.ParallelUniverse.setResourcesMode(ParallelUniverse.java:81)
at org.robolectric.RobolectricTestRunner.configureSandbox(RobolectricTestRunner.java:235)
at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:230)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:130)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:42)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.robolectric.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:84)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
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:498)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
This is what i have tried so far but nothing works. 到目前为止,这是我尝试过的,但是没有任何效果。
1. https://github.com/robolectric/robolectric/issues/4271 1. https://github.com/robolectric/robolectric/issues/4271
2. Robolectric: NullPointerException in setupActivity() 2. Robolectric:setupActivity()中的NullPointerException
3. https://github.com/robolectric/robolectric/issues/2579 3. https://github.com/robolectric/robolectric/issues/2579
I have already filed the issue 我已经提出了问题
Any help would be appreciated. 任何帮助,将不胜感激。
Solved by this answer on my issue 这个问题解决了我的问题
That Gradle config is picking up different versions of robolectric dependencies 该Gradle配置正在获取不同版本的robolectric依赖项
It would expect that we don't need to explicitly depend on resources or shadows core since those would be brought intransitively. 可以期望我们不需要显式依赖资源或影子核心,因为这些资源或影子会以非传递方式被带来。 So try the following 所以尝试以下
robolectricVersion = '4.0.2'
robolectric : "org.robolectric:robolectric:${robolectricVersion}",
shadowsSupport : "org.robolectric:shadows-support-v4:${robolectricVersion}",
shadowsMultidex: "org.robolectric:shadows-multidex:${robolectricVersion}",
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.