简体   繁体   中英

Error:Conflict with dependency 'com.android.support:support-v4' in project ':app'. Resolved versions for app (25.3.1) and test app (23.1.1) differ

I get this error every time i am trying to add dependency of Esspreso UI test library by the following dependency to use it in developing UI test for RecyclerView to get RecyclerViewActions.

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

while deleting previous dependency gradle is building perfectly can anyone help me selving this problem?? Sample from my gradle :

 dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
       compile 'com.android.support:appcompat-v7:25.3.1'
        compile 'com.android.support.constraint:constraint-layout:1.0.2'
        compile 'com.android.support:recyclerview-v7:25.3.1'
        compile 'com.android.support:cardview-v7:25.3.1'
        compile 'com.squareup.okhttp3:okhttp:3.6.0'
        compile 'com.github.bumptech.glide:glide:4.0.0-RC0'
        testCompile 'junit:junit:4.12'

        compile 'com.jakewharton:butterknife:8.6.0'
        annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
        annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0-RC0'

        compile 'com.google.android.exoplayer:exoplayer:r2.2.0'

        androidTestCompile( 'com.android.support.test.espresso:espresso-intents:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        androidTestCompile( 'com.android.support.test:rules:0.5', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        androidTestCompile ('com.android.support.test:runner:0.5', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        androidTestCompile ('com.android.support.test.espresso:espresso-web:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        androidTestCompile( 'com.android.support.test.espresso:espresso-contrib:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })

    }

Update

After googling for an hour I found the solution within Vogella by setting this dependency as following:

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

This would solve your problem:

androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2') {
    exclude group: 'com.google.code.findbugs'
    exclude group: 'com.android.support', module: 'appcompat-v7'
    exclude group: 'com.android.support', module: 'support-v4'
    exclude group: 'com.android.support', module: 'design'
    exclude module: 'recyclerview-v7'
}

You need to just exclude every library you have already provided in build.gradle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM