您好,我正在尝试启动 ActionBar
Activity UnitTests,并且我正在使用 Robolectirc-RC2
,但是当我尝试同步时我的 android studio 我收到以下错误/警告。
警告:与依赖org.hamcrest:hamcrest-core
冲突。应用程序和测试应用程序的已解决版本有所不同。
知道如何解决吗?
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'
最佳答案
好的解决方案是添加以下代码。
configurations.all {
resolutionStrategy {
force 'org.hamcrest:hamcrest-core:1.3'
}}
然后替换为How can we access context of an application in Robolectric? 仅用于版本 1.x 和 2.x:
Robolectric.application;
对于 3.x 版本:
运行时环境.application;
另外替换
配置(emulateSdk = 18,reportSdk = 18, list =“src/test/AndroidManifest.xml”)
与
@Config(sdk = 18)
关于android-studio - Robolectric 3.0-rc2 Hamcrest 核心冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30352553/