Android dependency 'com.android.support:appcompat-v7' has different version for the compile (26.1.0) and runtime (27.1.1) clas..

1,818 阅读1分钟
原文链接: www.jianshu.com

Error:Execution failed for task ':app:preDebugBuild'.

Android dependency 'com.android.support:appcompat-v7' has different version for the compile (26.1.0) and runtime (27.1.1) classpath. You should manually set the same version via DependencyResolution

图片
解决

方法一: 在app的build.gradle中的dependencies里添加:

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

方法二: 将app的build.gradle中的dependencies里的

    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

换成之前不报错的版本,例如我之前不报错的版本为

    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

同步一下就可以了