UI测试导入Espresso时的冲突

  • 以下是主要针对android studio导入包引发错误解决方法

用Espresso做UI测试时会导入下面一些包

dependencies {
  androidTestCompile 'com.android.support.test:runner:0.4'
  // Set this dependency to use JUnit 4 rules
  androidTestCompile 'com.android.support.test:rules:0.4'
  // Set this dependency to build and run Espresso tests
  androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
}

当导入这些包时,如果support-annotations.jar与Espresso版本不匹配时,

就会报出下面的错误:

Error:Conflict with dependency ‘com.android.support:support-annotations’. Resolved versions for app (22.0.0) and test app (23.0.1) differ.

这有两种解决方法:

方法一:

就按提示把你的support-annotations改成需要的版本。改完后你会发现之前写的SDK版本号不符和其它包不符时,这时也要连带着一起去改那些版本号。这时都改完后,你应用中有网络请求时会发现有些http老版的包不能用,这时在build.gradle里面加上下面这句话:

android {
    ......
//继续引用这个包
    useLibrary 'org.apache.http.legacy'
    ......
    }

当代码写到后期代码量多时改动量稍微有点大

方法二:

相对于上面的方法就简单多了,只需要忽略support-annotations的版本问题就可以了

dependencies {
......
 androidTestCompile ('com.android.support.test:runner:0.4'){
        exclude module: 'support-annotations'
    }
    androidTestCompile ('com.android.support.test:rules:0.4'){
        exclude module: 'support-annotations'
    }
    androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2.1'){
        exclude module: 'support-annotations'
    }
    ......
    }
感谢大家的支持
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值