解决Error:Execution failed for task ':app:preDebugAndroidTestBuild'. > Conflict with dependency 'co...

这个错误几乎都是依赖冲突所造成的 所以下面介绍三种解决办法

第一种

有些时候你的依赖有冲突就是不同依赖里面有相同的库 但是版本都不相同

 implementation ('com.jcodecraeer:xrecyclerview:1.5.9'){
        exclude group:'com.android.support'
    }

当你导入xrecyclerview的时候会与系统自带的

implementation'com.android.support:appcompat-v7:27.1.1'

这个版本冲突 所以在xrecyclerview依赖后面加上一句

exclude group:'com.android.support'

来清除xrecyclerview自带的support就不会有冲突了

第二种

直接把系统自带implementation'com.android.support:appcompat-v7:27.1.1'注释掉也可以 不过这种办法不建议使用 治标不治本

第三种

项目中不同Module的support包版本冲突怎么办?
只需要将以下代码复制到每个模块的build.gradle(Module:xxx)文件的根目录即可:
// 统一当前Module的所有support包版本

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '28.0.0'
            }
        }
    }
}

模板代码如下:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        ...
    }
    buildTypes {
        ...
    }

    lintOptions {
       ...
    }
}

dependencies {
    ...
}

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '28.0.0'
            }
        }
    }
}

你可能感兴趣的:(解决Error:Execution failed for task ':app:preDebugAndroidTestBuild'. > Conflict with dependency 'co...)