我正在使用 Espresso 来自动化我的应用测试。我的应用程序有1个ActionBarActivity和1个片段,使用android.support.v4.app.Fragment。该应用程序工作正常,但当我尝试运行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。 提前谢谢!
答案 0 :(得分:2)
从espresso-contrib库中排除support-v4。
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2') {
exclude module: 'support-v4'
}