错误:与项目':app'中的依赖项'com.android.support:support-annotations'冲突

时间:2017-12-13 17:40:18

标签: android gradle dependencies version

我试图解决这个gradle错误。我从我的一个朋友那里获得了这个项目。它完美地在他的系统中工作。好像我在我的gradle中有以下问题。

错误:与项目':app'中的依赖项'com.android.support:support-annotations'冲突。 app(27.0.2)和测试app(25.4.0)的已解决版本有所不同。

以下是我的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 个答案:

答案 0 :(得分:1)

只需在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.+'
    }
}

答案 1 :(得分:0)

您的espresso已经具有与上面针对不同版本的支持库所声明的相同的依赖关系,这会导致问题,因此从模块 build.gradle 文件中排除下面的主题

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

这里应该是什么样子

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

并且您的项目级build.gradle文件不应再次声明这些依赖项。

答案 2 :(得分:0)

刚刚添加了这个



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