Android Espresso Issue - Dependency conflict

前端 未结 8 1890
Happy的楠姐
Happy的楠姐 2021-02-12 16:34

I\'m trying to integrate espresso into my application for ui testing. Here are my dependencies in Gradle

dependencies {
    compile fileTree(dir: \'libs\', inclu         


        
相关标签:
8条回答
  • 2021-02-12 17:04

    I had to combine the following versions for L release after receiving a similar dependency conflict between project and test app:

    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'
    }
    

    useLibrary was needed since we use org.apache.http imports, see https://github.com/bitstadium/HockeySDK-Android/issues/80

    0 讨论(0)
  • 2021-02-12 17:04

    As stated in the google documentation: https://sites.google.com/a/android.com/tools/tech-docs/new-build-system/user-guide#TOC-Resolving-conflicts-between-main-and-test-APK

    The way to resolve is to explicitly set the support library in androidTestCompile to the version you are using in the project.

    if for example you are using support library version 25.0.1 just add

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

    in your build.gradle configuration

    0 讨论(0)
  • 2021-02-12 17:04

    New version of espresso-contrib 2.2.2 library has now dependency on com.android.support:appcompat-v7:23.1.1 resulting into conflict when using different version of appcompat-v7 in our compile time dependency like below:

    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'
    }
    

    To avoid conflict when we exclude appcompat-v7 dependency from espresso-contrib like below it breaks again due to some value dependencies on design support lib.

    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'
    }
    

    Error:

    Error:(69) Error retrieving parent for item: No resource found that matches the given name 'TextAppearance.AppCompat.Display1'.

    So, the solution to above problem is to exclude 'design-support' lib depedency from espresso-contrib like below:

    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'
    }
    

    That solves the conflict problem!

    For more detailed version of the answer you could check my other answer

    0 讨论(0)
  • 2021-02-12 17:07

    just change compile com.android.support:support-annotations:22.2.0 to 23.0.1 if want to use 2.2.1 version

    0 讨论(0)
  • 2021-02-12 17:14

    Latest versions of androidTest dependencies depend on appropriate version of support-annotations lib. In my case it is:

    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'
    

    Also, as a workaround you can add the next code in your build.gradle, android{} section:

    configurations.all {
       resolutionStrategy {
           force 'com.android.support:support-annotations:23.0.1'
       }
    }
    
    0 讨论(0)
  • 2021-02-12 17:14

    In the Jake Wharton U2020 application it is solved in the next way

    Add to you gradle.build file

    configurations.all {
        resolutionStrategy {
            force 'com.android.support:support-annotations:23.0.1'
        }
    }
    
    0 讨论(0)
提交回复
热议问题