1

I was trying to solve this gradle error.I imported this project by getting it from a friend of mine.It worked in his system perfectly. Seems like I have a The following issues in my gradle.

Error:Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (27.0.2) and test app (25.4.0) differ.

The following are my gradle

Module app

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.2"
    defaultConfig {
        applicationId "com.startup.hospital"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:27.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:design:27.+'
    compile 'com.android.support:support-vector-drawable:27.0.2'
    compile 'com.android.support:support-v4:27.0.2'
    compile 'com.aurelhubert:ahbottomnavigation:2.1.0'
    compile 'com.github.arimorty:floatingsearchview:2.1.1'
    compile 'com.ss.bottomnavigation:bottomnavigation:1.5.2'
    compile 'jp.wasabeef:glide-transformations:2.0.2'


    compile 'junit:junit:4.12'
    androidTestCompile 'com.android.support.test:runner:1.0.1'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.1'
}

Project gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.1"
    defaultConfig {
        applicationId "com.startup.hospital"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:27.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:design:27.+'
    compile 'com.android.support:support-vector-drawable:27.0.2'
    compile 'com.android.support:support-v4:27.0.2'
    compile 'com.aurelhubert:ahbottomnavigation:2.1.0'
    compile 'com.github.arimorty:floatingsearchview:2.1.1'
    compile 'com.ss.bottomnavigation:bottomnavigation:1.5.2'
    compile 'jp.wasabeef:glide-transformations:2.0.2'


    compile 'junit:junit:4.12'
    androidTestCompile 'com.android.support.test:runner:1.0.1'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.1'
}

3 Answers3

1

Just add the following in your build.gradle (:app)

configurations.all {
    resolutionStrategy {
        force 'com.android.support:appcompat-v7:26.+'
        force 'com.android.support:support-compat:26.+'
        force 'com.android.support:support-core-ui:26.+'
        force 'com.android.support:support-annotations:26.+'
        force 'com.android.support:recyclerview-v7:26.+'
    }
}
Sumukh Bhandarkar
  • 386
  • 1
  • 5
  • 14
0

Your espresso has already those dependencies same as you have declared above for support library with different version which is causing problem so exclude theme like below from module build.gradle file

  androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.1', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

here is what it should look like

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.2"
    defaultConfig {
        applicationId "com.startup.hospital"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:27.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:design:27.+'
    compile 'com.android.support:support-vector-drawable:27.0.2'
    compile 'com.android.support:support-v4:27.0.2'
    compile 'com.aurelhubert:ahbottomnavigation:2.1.0'
    compile 'com.github.arimorty:floatingsearchview:2.1.1'
    compile 'com.ss.bottomnavigation:bottomnavigation:1.5.2'
    compile 'jp.wasabeef:glide-transformations:2.0.2'


    compile 'junit:junit:4.12'
    androidTestCompile 'com.android.support.test:runner:1.0.1'
    androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.1', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

and Your project level build.gradle file should not have those dependencies declared again.

vikas kumar
  • 10,447
  • 2
  • 46
  • 52
0

just added this

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