版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_37283570/article/details/80198969
刚开学做项目运行AS编译器,发生如下错误
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中的compileSdkVersion,产生所依赖的dependency与当前版本不一致导致的。
上网查询了一些解决方法总结如下:
解决方法一:
build->Rebuid-project
上面这种方法亲测可行
解决方法二:
在build.gradle中将
implementation 'com.android.support:appcompat-v7:26.1.0' androidTestImplementation 'com.android.support:support-annotations:26.1.0'
修改为最新的版本(27.1.1) :
implementation 'com.android.support:appcompat-v7:27.1.1'
androidTestImplementation 'com.android.support:support-annotations:27.1.1'
同时更正build.gradle中的compileSdkVersion和targetSdkVersion版本为27:
compileSdkVersion 27 defaultConfig { applicationId "com.hero" //改成自己的applicationId minSdkVersion 'P' targetSdkVersion 27 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" }