简体   繁体   中英

java.lang.IllegalAccessError while using Robolectric 3.6.1

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)

截图

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

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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