AS报错:Error:Execution failed for task ':app:preDebugAndroidTestBuild'. > Conflict with dependency 'com.and

build->Rebuid-project

寻找错误根源:
报错里可以发现:

Resolved versions for app (26.1.0) and test app (27.1.1) differ

于是便查看app下build.gradle文件,发现并没有错误compileSdkVersion 为26,可是没有发现27.1.1版本的com.android.support:support-annotations。可是上述信息明显是版本冲突,于是在external library中寻找

发现了依赖包冲突。于是根据自己的编译版本删除多余的包27.1.1(笔者compileSdkVersion 为26),rebuild后问题解决。可是重启以后问题还会复现。于是上网继续寻找方法。再尝试了很多方法后,找到了一个方法解决了该问题。解决方法如下:

在app下的build.gradle文件中的dependences {}中添加如下代码:

androidTestCompile('com.android.support:support-annotations:26.1.0') {
        force = true
    }

添加后dependences中结构类似

dependencies {
  androidTestCompile('com.android.support:support-annotations:26.1.0') {
        force = true
    }
...
}

猜你喜欢

转载自www.cnblogs.com/wbyixx/p/12284290.html