Android构建项目时出现的小bug们(2018年5月19日19:31:20)

问题详情

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.

还有另外一种形式

  PS: 2018年5月11日18:54:56 今天换成家里的电脑发现另外一种新的异常,解决方式同上。。总之,提示你改成哪个具体版本就改成哪个。。。

Error:FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':sq_design:preDebugAndroidTestBuild'.
> Conflict with dependency 'com.android.support:support-annotations' in project ':sq_design'. Resolved versions for app (27.1.0) and 
test app (27.1.1) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 23s

它们的产生原因

由于你新建的项目时候选择的目标版本27(build.gradle→compileSdkVersion & targetSdkVersion)高于你当前的构建工具版本26.1.0(build.gradle→buildToolsVersion),就会出现上面的问题。

多说一句,buildToolsVersion版本必须 >= compileSdkVersion版本,因为Android是向下兼容的,高版本的build-tools可以构建低版本的Android App。

两种解决方式

一、简单方式

   如果不想改动版本号,直接把v7包!v7包!v7包!改成 如上错误信息中的推荐版本(eg:26.1.0→27.1.1)。。重新编译即可通过。

(如果觉得有红线不爽,可以试试方式二)

   

二、推荐方式

  上面的方法并不能从根本上解决问题,每次新建项目的时候都要手动去改动,而且会报红线,因为你的构建工具版本和依赖库的版本没对应上。

  1. 要么降低你的版本号,比如说修改build.gradle中的buildToolsVersion为26.1.0,跟compileSdkVersion和targetSdkVersion版本26对应上;
  2. 推荐!既然想体验高版本的特性,就得有构建得了这个版本的build tool --目前新版的SDK Tools还不能生成默认的配置,后面的版本会好些吧。 下载高版本的BuildTools:

原文地址:https://www.cnblogs.com/jooy/p/8949481.html