Recently, I encountered the following problems when using robolectric unit test:
It has been reported that the resource class cannot be found, so it needs to be added to gradle under the app (the code is manually typed, there may be an error, sorry)
testOptions{
unitTests{
includeAndroidResources = true
}
}
After adding the above code, there is an error in the title, specifically android.test.monitor2… This can’t be found. Each time sync takes a long time, and then report the same error. Refer to the following link article, but it doesn’t help me much.
Ask colleagues for help. After comparing our configurations, we found that the gradle version references are different (gradle/wrapper/gradle wrapper. Properties). The previous references are:
distributionUrl:=https\://service.gradle.org/distributions/gradle-5.4.1-all.zip
Mine is taken directly from the company mapping Maven library. It is a local reference with a lower version:
distributionUrl:=../../../../tools/gradle-4.1-all.zip
I changed the gradle configuration according to her configuration and synced again. The problem was solved.