Android studio更新到2.2之后出现的问题

来源:互联网 发布:汕头美工培训机构 编辑:程序博客网 时间:2024/05/16 01:02

更新完AS之后去写作业,发现怎么弄都是没法运行,提示的错误是Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (22.2.1) and test app (23.1.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.

大致意思就是说你测试版本用的库和最终用的库版本号不一致

打开后面给的链接发现真的是什么都没说啊!百度了半天没有找到什么中文资料,只能看看国外的网站有什么相关的解决方法。

折腾了好久大概总结出来问题在哪里了。写下来帮大家解决这个问题。

首先先定位问题出现在哪里,build.gradle里面的dependencies里面

dependencies {    compile fileTree(dir: 'libs', include: ['*.jar'])    compile 'com.android.support:appcompat-v7:22.2.1'    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha1'    testCompile 'junit:junit:4.12'    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'    androidTestCompile 'com.android.support.test:runner:0.5'    androidTestCompile 'com.android.support:support-annotations:23.1.1'}
一眼瞅过去肯定以为只要把最后一项

com.android.support:support-annotations:23.1.1

后面修改为22.2.1就行了是吧?naive。

我这么试了发现根本就不行。查了好久才发现并不只是这一句有问题,在google之后http://stackoverflow.com/questions/28999124/resolved-versions-for-app-22-0-0-and-test-app-21-0-3-differ给出了一些解释。

Looks like it's espresso-contrib

+--- com.android.support.test:testing-support-lib:0.1 (*)\--- com.android.support.test.espresso:espresso-contrib:2.0     +--- com.android.support:recyclerview-v7:21.0.3     |    +--- com.android.support:support-annotations:21.0.3     |    \--- com.android.support:support-v4:21.0.3     |         \--- com.android.support:support-annotations:21.0.3     +--- com.android.support:support-v4:21.0.3 (*)     \--- com.android.support.test.espresso:espresso-core:2.0 (*)
参考过后就知道了,就是说下面的androidTestCompile项目中,espresso那一项当中还有包含23.1.1的引用,你要是把androidTestCompile那几条都注释了再运行就发现编译通过了。。。

下面有人回答说Actually it's a bug of new update version of Espresso Contrib

好吧,有幸遇到这种存在在环境中的bug了,给出的解决方法简单粗暴,添加force强制指定annotations

configurations.all {    resolutionStrategy.force 'com.android.support:support-annotations:22.1.0'}
把这一项添加到dependencies里面就可以了。再去试一试
dependencies {    compile fileTree(dir: 'libs', include: ['*.jar'])    compile 'com.android.support:appcompat-v7:22.2.1'    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha1'    testCompile 'junit:junit:4.12'    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'    androidTestCompile 'com.android.support.test:runner:0.5'    androidTestCompile 'com.android.support:support-annotations:22.2.1'    configurations.all {        resolutionStrategy.force 'com.android.support:support-annotations:22.1.0'    }}
终于build successful

1 0
原创粉丝点击