Error:Execution failed for task ':app:prepareDebugAndroidTestDependencies'. > Dependency Error. See console for details

…衆ロ難τιáo~ 提交于 2019-12-10 12:35:59

问题


Error:Execution failed for task ':app:prepareDebugAndroidTestDependencies'.

Dependency Error. See console for details.

After adding the the following dependencies in app.gradle file -

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'

Console Logs -

Information:Gradle tasks [:app:clean, :app:generateDebugSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:generateDebugAndroidTestSources, :app:assembleDebug] Warning:Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (25.0.0) and test app (23.1.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details. Error:Execution failed for task ':app:prepareDebugAndroidTestDependencies'.

Dependency Error. See console for details. Information:BUILD FAILED Information:Total time: 28.459 secs Information:1 error Information:1 warning Information:See complete output in console


回答1:


I got the same probleme,when I add the following code in my app's build.gradle within android { },that's ok. configurations.all { resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.1' } you can get reason in this page
Execution failed for task 'app:prepareDebugAndroidTestDependencies'




回答2:


You need to add this line to your dependencies:

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

to force using the latest version of library

You can also try to exclude conflict packages like I did for espresso-contrib library

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:


This happen because of library version conflict in the debug app and test app. Add this under android{} tag

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


来源:https://stackoverflow.com/questions/40394736/errorexecution-failed-for-task-apppreparedebugandroidtestdependencies-de

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!