我正在使用Espresso来自动化我的应用程序测试。我的应用使用android.support.v4.app.Fragment有1个ActionBarActivity和1个片段。该应用程序运行正常,但是当我尝试运行Espresso测试时,启动应用程序时出现错误。

java.lang.NoSuchMethodError: No static method isLaidOut(Landroid/view/View;)Z in class Landroid/support/v4/view/ViewCompat; or its super classes (declaration of 'android.support.v4.view.ViewCompat' appears in /data/app/com.example.android.app.test-1/base.apk)
    at android.support.v7.internal.widget.ContentFrameLayout.setDecorPadding(ContentFrameLayout.java:73)
    at android.support.v7.app.AppCompatDelegateImplV7.applyFixedSizeWindow(AppCompatDelegateImplV7.java:428)
    at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:403)
    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:246)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
    at com.example.android.app.activities.MainActivity.onCreate(MainActivity.java:28)
    at android.app.Activity.performCreate(Activity.java:5933)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
    at android.support.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:346)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2407)
    at android.app.ActivityThread.access$800(ActivityThread.java:149)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:211)
    at android.app.ActivityThread.main(ActivityThread.java:5321)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)

    Test running failed: Instrumentation run failed due to 'java.lang.NoSuchMethodError'


我正在使用Android Studio。
提前致谢!

最佳答案

从espresso-contrib库中排除support-v4。

   androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2') {
         exclude module: 'support-v4'
   }

关于android - 带有support.v4的Espresso ViewCompat在加载时抛出NoSuchMethodError,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31006035/

10-12 04:23