Robolectric 3.0-rc2 Hamcrest-core冲突 [英] Robolectric 3.0-rc2 Hamcrest-core conflict
问题描述
您好,我试图获取 ActionBar
活动UnitTest,并且我正在使用 Robolectirc-RC2
,但是当我尝试同步Android Studio时,出现以下错误/警告。
警告:具有依赖性 org.hamcrest:hamcrest-core
的冲突。应用和测试应用的解析版本不同。
知道如何解决吗?
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'
推荐答案
好的解决方案是添加以下代码。
ok the solution was to add the following code.
configurations.all {
resolutionStrategy {
force 'org.hamcrest:hamcrest-core:1.3'
}}
,然后根据每个
仅用于1.x和2.x版本:
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;
对于版本3.x:
RuntimeEnvironment.application;
另外替换
Config(emulateSdk = 18,reportSdk = 18,清单= src / test / AndroidManifest.xml)
with
@Config(sdk = 18)
这篇关于Robolectric 3.0-rc2 Hamcrest-core冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!