android studio中AndroidJUnit4单元测试注解错误和recyclerview-v7 版本冲突
16lz
2021-01-23
bulid.gradle中的dependencies的依赖jar包错误recyclerview-v7
There are some combinations of libraries, or tools and libraries, that are incompatible, or can lead to bugs. One such incompatibility is compiling with a version of the Android support libraries that is not the latest version (or in particular, a version lower than your targetSdkVersion.)
原因:因为RecyclerView控件所依赖的android-support-v4包版本不一致造成的,即项目本身使用了一个appcompat的依赖(appcompat中包含了android-support-v4.jar),而这个support-v4和RecyclerView依赖的support-v4不是一个版本
解决办法:
compile 'com.android.support:recyclerview-v7:25.3.1'compile 'com.android.support:cardview-v7:25.3.1'compile 'com.android.support:support-v4:25.3.1'compile 'com.android.support:design:25.3.1'compile 'com.android.support:appcompat-v7:25.3.1'
给v7包和v4包设置相同的版本
junit4单元测试(只是告诉程序启动测试,和导入jar包,但有时总会出错)
1. AndroidManifest.xml,在这个配置文件中
<uses-library android:name="android.test.runner" />2. 在build.gradle module:app这个配置文件中
//运行时的集成测试环境(不确切,但就像汽车的发动机引擎)
defaultConfig 中添加testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
dependencies 中添加
//单元测试,指定版本号和依赖包androidTestCompile 'junit:junit:4.12'androidTestCompile ('com.android.support.test:runner:0.5')androidTestCompile 'com.android.support.test:rules:0.5'androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2.2')
更多相关文章
- 一个测试ok的popupwindow demo
- Android 子线程测试
- android 各版本与api值 对应表
- android 仿微信5版本实现滑动导航条
- Android 系统名字、版本、API level的对应关系
- 如何在Android单元测试中调试async-http
- android p cts camera测试 android.hardware.camera2.cts.Captur
- adnroid(10)(android下的单元测试)
- Android各版本源码下载链接