【问题标题】:Android Espresso Issue - Dependency conflictAndroid Espresso 问题 - 依赖冲突
【发布时间】:2015-08-04 10:43:39
【问题描述】:

我正在尝试将 espresso 集成到我的应用程序中以进行 ui 测试。这是我在 Gradle 中的依赖项

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:design:22.2.1'
    compile 'com.github.bumptech.glide:okhttp-integration:1.3.1@aar'
    compile 'com.squareup.okhttp:okhttp:2.0.0'
    compile 'de.hdodenhof:circleimageview:1.3.0'
    compile 'com.android.support:cardview-v7:21.+'
    compile 'com.android.support:recyclerview-v7:21.+'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
    androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2'
    compile 'com.android.support:support-annotations:22.2.0'
    androidTestCompile 'com.android.support.test:runner:0.3'
    compile project(':common')
    compile project(':service')
}

所以我所有的 espresso 依赖项都包括在内。但是,当我尝试构建时,出现此错误:

Warning:Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (22.2.1) and test app (22.2.0) differ.

有人遇到过吗?我发现它报告了here,但是没有解决方案。有没有人解决这个问题?

【问题讨论】:

  • 解决方法是使用'configurations.all { resolutionStrategy.force 'com.android.support:support-annotations:22.1.0' }'
  • 嘿,您必须从每个 espresso 依赖项中删除 android.support 依赖项。检查:stackoverflow.com/questions/29857695/…

标签: android android-gradle-plugin android-espresso


【解决方案1】:

espresso-contrib 2.2.2 库的新版本现在依赖于com.android.support:appcompat-v7:23.1.1,导致在我们的compile 时间依赖项中使用不同版本的appcompat-v7 时发生冲突,如下所示:

dependencies {
     compile fileTree(dir: 'libs', include: ['*.jar'])
     testCompile 'junit:junit:4.12'
     compile 'com.android.support:appcompat-v7:23.4.0'

     androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2'
}

为避免在我们从 espresso-contrib 中排除 appcompat-v7 依赖项时发生冲突,如下所示,由于对 design support 库的某些值依赖项,它再次中断。

androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2'){
    exclude module: 'support-annotations'
    exclude module: 'support-v4'
    exclude module: 'support-v13'
    exclude module: 'recyclerview-v7'
    exclude module: 'appcompat-v7'
}

错误:

错误:(69) 检索项目的父项时出错:找不到与给定名称“TextAppearance.AppCompat.Display1”匹配的资源。

因此,上述问题的解决方案是从espresso-contrib 中排除“设计支持”库依赖关系,如下所示:

androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2'){
    exclude module: 'support-annotations'
    exclude module: 'support-v4'
    exclude module: 'support-v13'
    exclude module: 'recyclerview-v7'
    exclude module: 'design'
}

这样就解决了冲突问题!

更详细的答案可以查看我的另一个answer

【讨论】:

  • @Droidwala 这是最好的答案
【解决方案2】:

所以经过大量挖掘,我发现我需要更改支持注释的依赖关系。

所以我需要改变 compile 'com.android.support:support-annotations:22.2.0' 至 androidTestCompile 'com.android.support:support-annotations:22.+'

【讨论】:

【解决方案3】:

androidTest 依赖项的最新版本取决于 support-annotations 库的适当版本。在我的情况下是:

androidTestCompile 'com.android.support.test:runner:0.4'
androidTestCompile 'com.android.support.test:rules:0.4'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1'
androidTestCompile 'org.mockito:mockito-core:2.0.31-beta'

此外,作为一种解决方法,您可以在 build.gradle、android{} 部分中添加下一个代码:

configurations.all {
   resolutionStrategy {
       force 'com.android.support:support-annotations:23.0.1'
   }
}

【讨论】:

  • 添加配置。所有 { .. } 工作得很好。谢谢
  • 我知道这个答案可以解决问题。但是每个支持注释版本都可能依赖于不同的方法,所以要非常小心,因为依赖于支持注释的库可能会表现得很奇怪。
【解决方案4】:

在Jake Wharton U2020 application中通过下一个方式解决

加你gradle.build文件

configurations.all {
    resolutionStrategy {
        force 'com.android.support:support-annotations:23.0.1'
    }
}

【讨论】:

    【解决方案5】:

    在收到项目和测试应用之间类似的依赖冲突后,我不得不为 L 版本组合以下版本:

    android {
        useLibrary 'org.apache.http.legacy'
        compileSdkVersion 23
        buildToolsVersion '23.0.1'
        defaultConfig {    
            minSdkVersion 14
            targetSdkVersion 23
        }
    }
    dependencies {
        compile 'com.android.support:appcompat-v7:23.0.1'
        compile 'com.android.support:support-v4:23.0.1'
    
        androidTestCompile 'com.android.support.test:runner:0.4'
        androidTestCompile 'com.android.support.test:rules:0.4'
        androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
        androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1'
    }
    

    因为我们使用 org.apache.http 导入,所以需要 useLibrary,请参阅 https://github.com/bitstadium/HockeySDK-Android/issues/80

    【讨论】:

      【解决方案6】:

      问题出在这个文件中: android-sdk\extras\android\m2repository\com\android\support\test\runner\0.3\runner-0.3.pom

      这里:

      <dependency>
            <groupId>com.android.support</groupId>
            <artifactId>support-annotations</artifactId>
            <version>22.2.0</version>
            <scope>compile</scope>
      </dependency>
      

      如果你设置 22.2.1 而不是 22.2.0 它将起作用

      【讨论】:

        【解决方案7】:

        如谷歌文档中所述: https://sites.google.com/a/android.com/tools/tech-docs/new-build-system/user-guide#TOC-Resolving-conflicts-between-main-and-test-APK

        解决的方法是将androidTestCompile中的支持库显式设置为你在项目中使用的版本。

        例如,如果您使用支持库版本25.0.1,只需添加

        androidTestCompile 'com.android.support:support-annotations:25.0.1'
        

        在您的 build.gradle 配置中

        【讨论】:

          【解决方案8】:

          只需将编译 com.android.support:support-annotations:22.2.0 更改为 23.0.1 如果要使用2.2.1版本

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2018-01-28
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2017-10-19
            • 2020-10-02
            相关资源
            最近更新 更多