Espresso错误:与依赖项“com.android.support:support-v4”冲突。 app(24.2.0)和测试app(23.1.1)的已解决版本有所不同

时间:2016-09-10 08:33:19

标签: android gradle android-gradle android-espresso

我已升级到最新的API级别24,这是最新的API级别(在扭动时)无论如何它都会导致此错误消息。

  

错误:与依赖项“com.android.support:support-v4”冲突。 app(24.2.0)和测试app(23.1.1)的已解决版本有所不同。有关详细信息,请参阅http://g.co/androidstudio/app-test-app-conflict

那我怎么解决这个问题呢?
同样this page第二个回答可以解决问题,但是如果你想要包括 com.android.support.test.espresso:espresso-contrib:2.2.2 在你的当时这将导致4个更类似的错误信息 那么如何摆脱这4条额外的错误信息?

3 个答案:

答案 0 :(得分:2)

以下是我的Espresso build.gradle依赖项:

getSupportActionBar().show();

其中:

    androidTestCompile "com.android.support:support-annotations:$SUPPORT_VERSION"
    androidTestCompile "com.android.support.test.espresso:espresso-core:$ESPRESSO_VERSION"
    androidTestCompile 'com.android.support.test:runner:0.5'
    androidTestCompile "com.android.support.test.espresso:espresso-intents:$ESPRESSO_VERSION"
    /**
     * AccessibilityChecks
     * CountingIdlingResource
     * DrawerActions
     * DrawerMatchers
     * PickerActions (Time and Date picker)
     * RecyclerViewActions
     */
    androidTestCompile("com.android.support.test.espresso:espresso-contrib:$ESPRESSO_VERSION") {
        exclude group: 'com.android.support', module: 'appcompat'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude group: 'com.android.support', module: 'support-v7'
        exclude group: 'com.android.support', module: 'design'
        exclude module: 'support-annotations'
        exclude module: 'recyclerview-v7'
    }

如果您仍然遇到问题,请检查我的项目的ESPRESSO_VERSION = '2.2.2' 文件:https://github.com/piotrek1543/LocalWeather/blob/master/app/build.gradle

希望它会有所帮助

答案 1 :(得分:2)

我找到了解决方案(解决方法) 如果您单击下面的图片,您将注意到下面的图片,您将注意到错误信息

  

错误:与依赖项“com.android.support:support-v4”冲突。 app(24.2.0)和测试app(23.1.1)的已解决版本有所不同。有关详细信息,请参阅http://g.co/androidstudio/app-test-app-conflict

将用行
固定     configurations.all {resolutionStrategy.force "com.android.support:support-v4:23.1.0"}
它位于gradle文件的依赖项区域中
同样错误信息

  

错误:与依赖项“com.android.support:appcompat-v7”冲突。 app(24.2.0)和测试app(23.1.0)的已解决版本有所不同。有关详细信息,请参阅http://g.co/androidstudio/app-test-app-conflict

可以用线路固定 configurations.all {resolutionStrategy.force "com.android.support:appcompat-v7:23.1.0"} 等等,直到所有错误都解决了 请不要忘记here寻找主要解决方案(第二和第三个回答

My Solution

答案 2 :(得分:1)

您可以使用以下方法强制测试中的支持库:

androidTestCompile 'com.android.support:support-v4:24.2.0'