Robolectric 3.0-rc2 Hamcrest-core conflict

人走茶凉 提交于 2019-12-11 03:17:22

问题


Hello I'm trying to get ActionBar Activity UnitTests going and I'm using Robolectirc-RC2, but when i try to sync my android studio I'm getting the following error/warning. Warning:Conflict with dependency org.hamcrest:hamcrest-core. Resolved versions for app and test app differ. Any idea how to resolve it?

repositories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
mavenLocal()
mavenCentral()

}

dependencies {
// Unit testing dependencies
unitTestCompile('junit:junit:4.12') { // Prevent duplication conflicts
    exclude module: 'hamcrest-core'
    exclude module: 'hamcrest-library'
    exclude module: 'hamcrest-integration'
}
unitTestCompile 'org.hamcrest:hamcrest-core:1.1'
unitTestCompile 'org.hamcrest:hamcrest-library:1.1'
unitTestCompile 'org.hamcrest:hamcrest-integration:1.1'
unitTestCompile 'com.squareup.assertj:assertj-android:1.0.0'

回答1:


ok the solution was to add the following code.

configurations.all {
resolutionStrategy {
    force 'org.hamcrest:hamcrest-core:1.3'
}}

and then replace per How can we access context of an application in Robolectric? Just use for version 1.x and 2.x:

Robolectric.application;

And for version 3.x:

RuntimeEnvironment.application;

additionally replace

Config(emulateSdk = 18, reportSdk = 18, manifest = "src/test/AndroidManifest.xml")

with

@Config(sdk = 18)




回答2:


Here is how we specify Robolectric in our projects:

   testCompile("org.robolectric:robolectric:${robolectricVer}") {
        exclude group: 'commons-logging', module: 'commons-logging'
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'
    }


来源:https://stackoverflow.com/questions/30352553/robolectric-3-0-rc2-hamcrest-core-conflict

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!