使用Robolectric 3.6.1时的java.lang.IllegalAccessError

问题描述 投票:2回答:1

当我运行JUnit测试时,它会抛出以下错误: java.lang.IllegalAccessError: tried to access field org.robolectric.annotation.Config$Builder.sdk from class org.robolectric.RobolectricTestRunner$1

这似乎在RobolectricTestRunner.java(3.6.1)这里有错误

screenshots

屏幕截图中的代码位于robolectric-3.6.1-resources.jar

环境:

  • JUnit:4.12
  • Robolectric 3.6.1
  • Android Gradle插件:2.3.3
  • Android Studio:3.0.1
  • 操作系统:MacOS 10.13.2

有人可以帮帮我吗?这个

java android junit robolectric robolectric-gradle-plugin
1个回答
1
投票

最后,我弄清楚了什么是错的。在app/build.gradle中,我有以下依赖项:

testCompile 'junit:junit:4.12'
testCompile 'org.assertj:assertj-core:2.6.0'
testCompile 'org.robolectric:robolectric:3.6.1'
testCompile 'org.robolectric:shadows-multidex:3.2.2'

我在版本3.2.2中有shadows-multidex依赖项,其内部有org.robolectric:robolectric-annotations:3.2.2。因此,在我将shadow-multidex的版本更改为3.6.1作为robolectric版本后,一切都很好!

© www.soinside.com 2019 - 2024. All rights reserved.