2014-06-04 4 views
3

Я использую Double Espresso от Jake Wharton, который помогает с интеграцией Google Espresso в Android Studio и Gradle. Беда приходит с библиотекой совместимости (поддержка-v4), какие классы недоступны в тестовых сборках:Эспрессо в Android Studio и NoClassDefFoundError

java.lang.RuntimeException: Exception during suite construction 
at android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests.testSuiteConstructionFailed(TestSuiteBuilder.java:238) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191) 
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176) 
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554) 
at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onStart(GoogleInstrumentationTestRunner.java:167) 
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1840) 
Caused by: java.lang.reflect.InvocationTargetException 
at java.lang.reflect.Constructor.constructNative(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
at android.test.suitebuilder.TestMethod.instantiateTest(TestMethod.java:87) 
at android.test.suitebuilder.TestMethod.createTest(TestMethod.java:73) 
at android.test.suitebuilder.TestSuiteBuilder.addTest(TestSuiteBuilder.java:262) 
at android.test.suitebuilder.TestSuiteBuilder.build(TestSuiteBuilder.java:184) 
at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:379) 
at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onCreate(GoogleInstrumentationTestRunner.java:114) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5142) 
at android.app.ActivityThread.access$1500(ActivityThread.java:156) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1418) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:157) 
at android.app.ActivityThread.main(ActivityThread.java:5872) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1069) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:885) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.NoClassDefFoundError: net.skoumal.project.activity.MainActivity 
at net.skoumal.project.test.MainActivityTest.<init>(MainActivityTest.java:30) 
... 19 more 

ответ

2

решение очень просто, просто изменить эти строки в gradle.build:

androidTestCompile 'com.jakewharton.espresso:espresso:1.1-r3' 
androidTestCompile('com.jakewharton.espresso:espresso-support-v4:1.1-r3') 

путем добавления исключения для библиотеки совместимости:

androidTestCompile 'com.jakewharton.espresso:espresso:1.1-r3' 
androidTestCompile('com.jakewharton.espresso:espresso-support-v4:1.1-r3') { 
    exclude group: 'com.android.support' 
}