Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android version 24.0.0 and Espresso 2.0 gradle exception

I am trying to use Espresso 2.0 in my app,in order to test the UI elements. However the gradle doesn't let do it. It gives me this message

Error:Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (24.0.0) and test app (23.1.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.

This is my gradle file

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.0"

defaultConfig {
    applicationId "theo.testing.espressotutorial"
    minSdkVersion 14
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"


}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

packagingOptions{
    exclude 'LICENSE.txt'
  }
}

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

androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'

// Android JUnit Runner
androidTestCompile 'com.android.support.test:runner:0.5'
// JUnit4 Rules
androidTestCompile 'com.android.support.test:rules:0.5'
}

Should I updater the test runners? This is giving me a headache.

Thanks,

Theo.

like image 607
Theo Avatar asked Jul 04 '16 09:07

Theo


1 Answers

Espresso has transitive dependencies that cause those problems. You can just exclude all dependencies to the group com.android.support from your androidTest dependencies:

// Exclude Espresso's transitive dependencies to all packages in group com.android.support
configurations.androidTestCompile.dependencies.each { androidTestCompileDependency ->
    androidTestCompileDependency.exclude group: 'com.android.support'
}

You should use Espresso 2.2.2! A complete example:

dependencies {

    def espressoVersion = '2.2.2'
    def testRunnerVersion = '0.5'

    androidTestCompile "com.android.support.test:runner:${testRunnerVersion}"
    androidTestCompile "com.android.support.test:rules:${testRunnerVersion}"
    androidTestCompile "com.android.support.test.espresso:espresso-core:${espressoVersion}"
    androidTestCompile "com.android.support.test.espresso:espresso-contrib:${espressoVersion}"
    androidTestCompile "com.android.support.test.espresso:espresso-intents:${espressoVersion}"

    configurations.androidTestCompile.dependencies.each { androidTestCompileDependency ->
        androidTestCompileDependency.exclude group: 'com.android.support'
    }
}
like image 196
thaussma Avatar answered Nov 11 '22 22:11

thaussma