与项目“:app"中的依赖项"com.android.support:support-annotations"冲突.应用(26.1.0)和测试应用(27.1.1)的已解决版本不同. [英] 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.
问题描述
我是Android App开发的新手.当我尝试创建一个新项目Android Project时,弹出以下消息.
I am new to Android App Development. When I tried to create a new project,Android Project...the following message popped up..
错误:任务':app:preDebugAndroidTestBuild'的执行失败.
Error:Execution failed for task ':app:preDebugAndroidTestBuild'.
与项目':app'中的依赖项'com.android.support:support-annotations'冲突.应用(26.1.0)和测试应用(27.1.1)的已解决版本不同.参见 https://d.android.com/r/tools/有关详细信息,请参见test-apk-dependency-conflicts.html . 信息:Gradle任务[:app:generateDebugSources,:app:generateDebugAndroidTestSources,:app:mockableAndroidJar]
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. Information:Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar]
这是我的项目的屏幕截图 点击此处查看我遇到的错误的屏幕截图
This is the screenshot of my project 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 .. 也不可行.
i also tried adding this code to my dependency.. androidTestCompile 'com.android.support:support-annotations:23.3.0' this didn't work out. I also tried 27.1.1 and 26.1.0.. that didn't work out either.
推荐答案
根据您的屏幕截图,我找到了两个可行的解决方案:
Based on your screenshot i found two working solutions:
第一个解决方案:将此行添加到gradle模块的依赖项中
First solution: add to dependencies of your gradle module this line
compile 'com.android.support:support-annotations:27.1.1'
并同步您的项目
注意:如果您使用的是Android Studio 3+,请将compile
更改为implementation
Note: if you are using Android studio 3+ change compile
to implementation
第二个解决方案:配置文档在项目gradle中添加以下行:
in project gradle add this line:
// 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"
}
然后访问此部分,将compileSdkVersion
行更改为
Then to access this section change compileSdkVersion
line to be
compileSdkVersion rootProject.ext.compileSdkVersion
并在dependencies
部分将导入的库更改为如下所示:
and at dependencies
section change the imported library to be like this:
compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
并同步您的项目
注意:如果您使用的是Android Studio 3+,请将compile
更改为implementation
Note: if you are using Android studio 3+ change compile
to implementation
关于compile
和implementation
之间的区别,请看这里
实现和gradle编译之间有什么区别
For the difference between compile
and implementation
look at this
What's the difference between implementation and compile in gradle
这篇关于与项目“:app"中的依赖项"com.android.support:support-annotations"冲突.应用(26.1.0)和测试应用(27.1.1)的已解决版本不同.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!