【问题标题】:Error:Execution failed for task ':app:prepareDebugAndroidTestDependencies'. > Dependency Error. See console for details错误:任务“:app:prepareDebugAndroidTestDependencies”的执行失败。 > 依赖错误。详情见控制台
【发布时间】:2017-03-16 15:19:21
【问题描述】:

Error: 任务 ':app:prepareDebugAndroidTestDependencies' 执行失败。

依赖错误。详情见控制台。

在app.gradle文件中添加如下依赖后-

androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
// add this for intent mocking support
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.2'
// add this for webview testing support
androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2.2'

控制台日志 -

信息:Gradle 任务 [:app:clean, :app:generateDebugSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:generateDebugAndroidTestSources, :app:assembleDebug] 警告:与依赖项“com.android.support:support-annotations”冲突。应用程序 (25.0.0) 和测试应用程序 (23.1.1) 的已解决版本不同。有关详细信息,请参阅http://g.co/androidstudio/app-test-app-conflict。 错误:任务 ':app:prepareDebugAndroidTestDependencies' 执行失败。

依赖错误。有关详细信息,请参阅控制台。 信息:构建失败 信息:总时间:28.459 秒 信息:1个错误 信息:1 个警告 信息:在控制台中查看完整的输出

【问题讨论】:

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


    【解决方案1】:

    这是因为调试应用和测试应用中的库版本冲突。在 android{} 标签下添加这个

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

    【讨论】:

      【解决方案2】:

      您需要将此行添加到您的依赖项中:

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

      强制使用最新版本的库

      您也可以尝试排除冲突包,就像我为 espresso-contrib 库所做的那样

      dependencies {
          ext.JUNIT_VERSION = '4.12'
          ext.AA_VERSION = '4.0.0'
          ext.SUPPORT_VERSION = '24.1.1'
          ext.ESPRESSO_VERSION = '2.2.2'
      
      ...
      
          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'
          }
      

      【讨论】:

        【解决方案3】:

        我遇到了同样的问题,当我在我的应用程序的build.gradle 中的android { } 中添加以下代码时,没关系。 configurations.all { resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.1' } 你可以在这个页面找到原因
        Execution failed for task 'app:prepareDebugAndroidTestDependencies'

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-02-17
          • 1970-01-01
          • 2017-09-01
          • 1970-01-01
          相关资源
          最近更新 更多