- 以下是主要针对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'
}
......
}