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'
    
    检查此问题: