关于android studio 出现Error:Execution failed for task ':app:preDebugAndroidTestBuild'. 的解决办法

前段时间打开Android studio 在build过程中总会出现以下错误

Error:Execution failed for task ':app:preDebugAndroidTestBuild'.
> Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (26.1.0) and test app (27.1.1) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.

在参考了网上的解决办法:

build->Rebuid-project

后,重新build后发现问题解决了。可是每当新建文件,或者重启AS后又会出现此类情况,虽然可以解决,但是并不彻底。于是便寻找错误根源。仔细阅读发现问题

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中寻找


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
    }
...
}
最后修改时间2018.5.9

猜你喜欢

转载自blog.csdn.net/leansmall/article/details/80513769