android-studio - Robolectric 3.0-rc2 Hamcrest 核心冲突

标签 android-studio robolectric android-actionbaractivity

您好,我正在尝试启动 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/

相关文章:

unit-testing - 单元测试已启动的服务,其中注入(inject)了几个字段?

Android:Fragment 的 onOptionsItemSelected 没有被调用

android - 在 android studio (osx) 中使用 LLDB 时无法保存核心转储?

java - Robolectric、AsyncTasks 和线程

android - 测试 Activity 是否已使用 FLAG_ACTIVITY_CLEAR_TOP 启动

android-activity - v7-21 ActionBarActivity 不在左侧显示应用程序主图标

android - ActionBarActivity 和 FragmentActivity 中的 setContentView

java - Google 示例通用音乐播放器构建错误

android studio如何使用库模块中已经添加的库依赖项

android - CardView onTouch onClick