错误:任务’: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 07000 for details.
Information:Gradle tasks [:app:generateDebugSources,:app:generateDebugAndroidTestSources,:app:mockableAndroidJar]
这是我项目的截图
click here to see screenshot of the error i got
我也尝试将此代码添加到我的依赖项中..
androidTestCompile’com.android.support:support-annotations:23.3.0′
这没有成功.我也试过27.1.1和26.1.0 ..
这也没有成功.
compile 'com.android.support:support-annotations:27.1.1'
并同步你的项目
注意:如果您使用Android studio 3更改编译实现
第二种解决方案:配置文档https://developer.android.com/studio/build/gradle-tips.html#configure-project-wide-properties中的项目范围属性
在project gradle中添加以下行:
// This block encapsulates custom properties and makes them available to all // modules in the project. ext { // The following are only a few examples of the types of properties you can define. compileSdkVersion = 26 // You can also use this to specify versions for dependencies. Having consistent // versions between modules can avoid behavior conflicts. supportLibVersion = "27.1.1" }
然后访问此部分,将compileSdkVersionline更改为
compileSdkVersion rootProject.ext.compileSdkVersion
并在依赖项部分更改导入的库如下所示:
compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
并同步你的项目
注意:如果您使用Android studio 3更改编译实现
对于编译和实现之间的区别,请看这个
What’s the difference between implementation and compile in gradle