android studio中AndroidJUnit4单元测试注解错误和recyclerview-v7 版本冲突

 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')



你可能感兴趣的:(android)