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

更新完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.
希望走过的坑能够帮到你。若帮到你了,麻烦给买个棒冰吃。
这里写图片描述

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值