java.lang.IllegalAccessError while using Robolectric 3.6.1

360 Views Asked by At

While I run JUnit tests, it throws the following error:
java.lang.IllegalAccessError: tried to access field org.robolectric.annotation.Config$Builder.sdk from class org.robolectric.RobolectricTestRunner$1

It seems that there's sth wrong here in the RobolectricTestRunner.java(3.6.1)

screenshots

The code in the screenshot is in the robolectric-3.6.1-resources.jar

Environment:

  • JUnit: 4.12
  • Robolectric 3.6.1
  • Android Gradle Plugin: 2.3.3
  • Android Studio: 3.0.1
  • OS: MacOS 10.13.2

Anyone can help me? thks

1

There are 1 best solutions below

0
On

At last, I have figured out what's wrong. In the app/build.gradle, I had the following dependencies:

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'

I had the shadows-multidex dependencies in version 3.2.2, which had the org.robolectric:robolectric-annotations:3.2.2 internal. So, after I changed the version of shadow-multidex to 3.6.1 as the robolectric version, everything was fine!