Android 安卓如何在支持库24.1.1中使用Espresso 2.2.2?
这是我的测试:Android 安卓如何在支持库24.1.1中使用Espresso 2.2.2?,android,android-support-library,android-espresso,Android,Android Support Library,Android Espresso,这是我的测试: @RunWith(AndroidJUnit4.class) @MediumTest public class MainActivityTest { @Rule public ActivityTestRule<MainActivity> mainActivityActivityTestRule = new ActivityTestRule<MainActivity>(MainActivity.class); @Test p
@RunWith(AndroidJUnit4.class)
@MediumTest
public class MainActivityTest {
@Rule
public ActivityTestRule<MainActivity> mainActivityActivityTestRule = new ActivityTestRule<MainActivity>(MainActivity.class);
@Test
public void buttonShouldBePresent(){
Intents.init();
onView(withId(R.id.button)).perform(click());
intended(hasComponent(SecondActivity.class.getName()));
}
}
我得到这个错误:
Error:Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (24.1.1) and test app (23.1.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
已尝试将支持库与早期版本一起使用(可以成功导入,但无法使用TextInputItemText):
我可以导入早期版本,但有两个原因使我无法使用早期版本
- Android Studio 2.1+
- Android SDK平台工具24+
- Android SDK工具25+
- SDK构建工具24.0.0
- Android支持存储库34+
- Android SDK平台24
如何在不降低支持库版本的情况下解决此问题?从浓缩咖啡中排除
支持注释
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
您不能将支持库版本(例如24.x.x)与23.1.1支持注释混用,因此请删除以下内容:
configurations.all {
resolutionStrategy.force('com.android.support:support-annotations:23.1.1')
}
configurations.all {
resolutionStrategy.force('com.android.support:support-annotations:23.1.1')
}
configurations.all {
resolutionStrategy.force('com.android.support:support-annotations:23.1.1')
}
专业提示:
设计
取决于appcompat-v7
和recyclerview-v7
,因此您无需指定它们。有两种解决方案可以解决此问题:
- 最简单的方法是在依赖项中包含,这一行:
androidTestCompile'com.android.support:支持注释:24.1.1'
并删除此项:
configurations.all {
resolutionStrategy.force('com.android.support:support-annotations:23.1.1')
}
configurations.all {
resolutionStrategy.force('com.android.support:support-annotations:23.1.1')
}
configurations.all {
resolutionStrategy.force('com.android.support:support-annotations:23.1.1')
}
- 另一种方法是排除
android:support:annotations
libs:
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
module: 'support-annotations'
})
并删除此项:
configurations.all {
resolutionStrategy.force('com.android.support:support-annotations:23.1.1')
}
configurations.all {
resolutionStrategy.force('com.android.support:support-annotations:23.1.1')
}
configurations.all {
resolutionStrategy.force('com.android.support:support-annotations:23.1.1')
}
Espresso
及其所有工件,如web
或intents
正在使用版本23.1.1
及更旧版本的Android支持库(Espresso contrib
)
请注意,Android支持库的最新版本已经是24.2.0
,而不是24.1.1
希望这会有所帮助您可以使用以下命令在测试中强制使用注释库:
androidTestCompile 'com.android.support:support-annotations:24.1.1'
检查此问题: