0

Android 계측 테스트를 실행할 때 왜 예외가 발생합니까? Android 계측 테스트 : java.lang.RuntimeException : java.lang.NoClassDefFoundError : com.google.common.base.Optional

30416-30566/com.example.myapp I/TestRunner﹕ java.lang.RuntimeException: java.lang.NoClassDefFoundError: com.google.common.base.Optional 
     at com.google.android.apps.common.testing.ui.espresso.base.ThreadPoolExecutorExtractor.getAsyncTaskThreadPool(ThreadPoolExecutorExtractor.java:54) 
     at com.google.android.apps.common.testing.ui.espresso.base.BaseLayerModule.provideSdkAsyncTaskMonitor(BaseLayerModule.java:83) 
     at com.google.android.apps.common.testing.ui.espresso.base.BaseLayerModule$$ModuleAdapter$ProvideSdkAsyncTaskMonitorProvidesAdapter.get(BaseLayerModule$$ModuleAdapter.java:326) 
     at com.google.android.apps.common.testing.ui.espresso.base.BaseLayerModule$$ModuleAdapter$ProvideSdkAsyncTaskMonitorProvidesAdapter.get(BaseLayerModule$$ModuleAdapter.java:290) 
     at dagger.internal.Linker$SingletonBinding.get(Linker.java:364) 
     at com.google.android.apps.common.testing.ui.espresso.base.UiControllerImpl$$InjectAdapter.get(UiControllerImpl$$InjectAdapter.java:64) 
     at com.google.android.apps.common.testing.ui.espresso.base.UiControllerImpl$$InjectAdapter.get(UiControllerImpl$$InjectAdapter.java:19) 
     at dagger.internal.Linker$SingletonBinding.get(Linker.java:364) 
     at com.google.android.apps.common.testing.ui.espresso.base.BaseLayerModule$$ModuleAdapter$ProvideUiControllerProvidesAdapter.get(BaseLayerModule$$ModuleAdapter.java:176) 
     at com.google.android.apps.common.testing.ui.espresso.base.BaseLayerModule$$ModuleAdapter$ProvideUiControllerProvidesAdapter.get(BaseLayerModule$$ModuleAdapter.java:140) 
     at com.google.android.apps.common.testing.ui.espresso.ViewInteraction$$InjectAdapter.get(ViewInteraction$$InjectAdapter.java:67) 
     at com.google.android.apps.common.testing.ui.espresso.ViewInteraction$$InjectAdapter.get(ViewInteraction$$InjectAdapter.java:19) 
     at dagger.ObjectGraph$DaggerObjectGraph.get(ObjectGraph.java:272) 
     at com.google.android.apps.common.testing.ui.espresso.Espresso.onView(Espresso.java:51) 
     at com.example.espresso.myapp.filtering.MyTest.testSomething(MyTest.java:51) 
     at java.lang.reflect.Method.invokeNative(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:525) 
     at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214) 
     at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199) 
     at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192) 
     at junit.framework.TestCase.runBare(TestCase.java:134) 
     at junit.framework.TestResult$1.protect(TestResult.java:115) 
     at junit.framework.TestResult.runProtected(TestResult.java:133) 
     at junit.framework.TestResult.run(TestResult.java:118) 
     at junit.framework.TestCase.run(TestCase.java:124) 
     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:1738) 
Caused by: java.lang.NoClassDefFoundError: com.google.common.base.Optional 
     at com.google.android.apps.common.testing.ui.espresso.base.ThreadPoolExecutorExtractor$5.call(ThreadPoolExecutorExtractor.java:135) 
     at com.google.android.apps.common.testing.ui.espresso.base.ThreadPoolExecutorExtractor$5.call(ThreadPoolExecutorExtractor.java:130) 
     at java.util.concurrent.FutureTask.run(FutureTask.java:234) 
     at com.google.android.apps.common.testing.ui.espresso.base.ThreadPoolExecutorExtractor$1.run(ThreadPoolExecutorExtractor.java:76) 
     at android.os.Handler.handleCallback(Handler.java:730) 
     at android.os.Handler.dispatchMessage(Handler.java:92) 
     at android.os.Looper.loop(Looper.java:137) 
     at android.app.ActivityThread.main(ActivityThread.java:5419) 
     at java.lang.reflect.Method.invokeNative(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:525) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209) 
     at com. 

내 build.gradle입니다 :

apply plugin: 'com.android.application' 
apply plugin: 'com.neenbedankt.android-apt' 
apply plugin: 'android' 
apply plugin: 'robolectric' 

android { 
    compileSdkVersion 21 
    buildToolsVersion "21.1.0" 

    defaultConfig { 
     applicationId "com.example.myapp" 
     minSdkVersion 18 
     targetSdkVersion 21 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner" 
     testApplicationId 'com.example.myapptest' 
     testHandleProfiling true 
     testFunctionalTest true 
     multiDexEnabled true 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
    sourceSets { 
     androidTest { 
      setRoot('src/test') 
     } 
    } 

    packagingOptions { 
     exclude 'META-INF/LICENSE.txt' 
     exclude 'LICENSE.txt' 
     exclude 'META-INF/LICENSE' 
     exclude 'META-INF/NOTICE' 
     exclude 'META-INF/NOTICE.txt' 
    } 
    dexOptions { 
     jumboMode true 
    } 

} 

robolectric { 
    include '**/*Test.class' 
    exclude '**/espresso/**/*Test.class' 
} 

configurations { 
    apt 
} 

apt { 
    arguments { 
     // resourcePackageName android.defaultConfig.packageName 
     resourcePackageName 'com.example.myapp' 
     androidManifestFile variant.outputs[0].processResources.manifestFile 
    } 
} 

ext { 
    daggerVersion = '1.2.2'; 
    androidAnnotationsVersion = '3.2'; 
    robobindingVersion = '0.8.9'; 
    jodatimeVersion = '2.5.1'; 
    ormliteVersion = '4.48'; 
    ottoVersion = '1.3.5'; 
    commonsioVersion = '2.0.1'; 
    playservicesVersion = '6.1.71'; 
    supportv4Version = '21.0.2'; 
    javaxinjectVersion = '1'; 
    junitVersion = '4.11'; 
    robolectricVersion = '2.4'; 
} 

dependencies { 
    repositories { 
     mavenCentral() 
    } 

    androidTestCompile('com.jakewharton.espresso:espresso:1.1-r3') { 
     exclude group: 'com.squareup.dagger' 
     exclude group: 'com.google.guava', module: 'guava' 
     exclude group: 'com.android.support' 
     exclude group: 'org.hamcrest', module: 'hamcrest-integration' 
    } 
    androidTestCompile ('com.jakewharton.espresso:espresso-support-v4:1.1-r3') { 
     exclude group: 'com.squareup.dagger' 
     exclude group: 'com.google.guava', module: 'guava' 
     exclude group: 'com.android.support' 
     exclude group: 'org.hamcrest', module: 'hamcrest-integration' 
    } 

    androidTestCompile("junit:junit:${junitVersion}") { 
     exclude group: 'org.hamcrest' 
    } 

    androidTestCompile('com.squareup:fest-android:1.0.7') { 
     exclude group: 'com.android.support' 
    } 

    // androidTestCompile group: 'com.google.guava', name: 'guava', version: '16.0' 

    androidTestCompile("org.robolectric:robolectric:${robolectricVersion}") { 
     exclude module: 'classworlds' 
     exclude module: 'commons-logging' 
     exclude module: 'httpclient' 
     exclude module: 'maven-artifact' 
     exclude module: 'maven-artifact-manager' 
     exclude module: 'maven-error-diagnostics' 
     exclude module: 'maven-model' 
     exclude module: 'maven-project' 
     exclude module: 'maven-settings' 
     exclude module: 'plexus-container-default' 
     exclude module: 'plexus-interpolation' 
     exclude module: 'plexus-utils' 
     exclude module: 'wagon-file' 
     exclude module: 'wagon-http-lightweight' 
     exclude module: 'wagon-provider-api' 
    } 

    compile 'com.android.support:multidex:1.0.0' 
    apt("org.robobinding:codegen:$robobindingVersion") { 
     exclude group: 'com.google.guava', module: 'guava' 
    } 
    compile("org.robobinding:robobinding:$robobindingVersion:with-dependencies") { 
     exclude group: 'com.google.guava', module: 'guava' 
    } 
    apt "org.androidannotations:androidannotations:${androidAnnotationsVersion}" 
    compile "org.androidannotations:androidannotations-api:${androidAnnotationsVersion}" 
    apt("com.squareup.dagger:dagger-compiler:${daggerVersion}") { 
     // exclude group: 'com.google.guava', module: 'guava' 
    } 
    compile "com.squareup.dagger:dagger:${daggerVersion}" 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile "com.google.android.gms:play-services:${playservicesVersion}" 
    compile "com.android.support:support-v4:${supportv4Version}" 
    compile "com.squareup:otto:${ottoVersion}" 
    compile "javax.inject:javax.inject:${javaxinjectVersion}" 
    compile "com.j256.ormlite:ormlite-core:${ormliteVersion}" 
    compile "com.j256.ormlite:ormlite-android:${ormliteVersion}" 
    compile group: 'commons-io', name: 'commons-io', version: "${commonsioVersion}" 
    compile "net.danlew:android.joda:${jodatimeVersion}" 
} 

apply plugin: 'idea' 
idea { 
    module { 
     testOutputDir = file('build/test-classes/debug') 
    } 
} 

android.applicationVariants.all { variant -> 
    def aptOutput = file("${project.buildDir}/generated/source/apt/${variant.dirName}") 
    println "****************************" 
    println "variant: ${variant.name}" 
    println "manifest: ${variant.outputs[0].processResources.manifestFile}" 
    println "aptOutput: ${aptOutput}" 
    println "****************************" 

    variant.javaCompile.doFirst { 
     println "*** compile doFirst ${variant.name}"  
     aptOutput.mkdirs() 
     variant.javaCompile.options.compilerArgs += [ 
       '-processorpath', configurations.apt.getAsPath(), 
       '-AandroidManifestFile=' + variant.outputs[0].processResources.manifestFile, 
       '-s', aptOutput 
     ] 
    } 
} 

그리고 이것은 예외가 발생 내 코드의 라인 :

그것은 구아바 함께 할 수있는 뭔가가있을
onView(withId(R.id.a_button)).perform(click()); 

, 나는 그것을 적절하게 포함하거나 배제하는 방법을 모른다.

미리 감사드립니다.

답변

0

우선 Espresso 2.0이 출시되었으며 업그레이드해야 할 이유가 많이 있습니다 (그 중 Android L 지원).하지만 그건 당신의 문제가 아닙니다.

문제가 아니어도 디버그 빌드에 신경을 쓰지 않는 것처럼 보입니다.

수많은 패키지에서 구아바를 제외하는 것처럼 보입니다. 프로젝트 디렉토리의 명령 줄에

./gradlew dependencies 

을 실행하면 구아바가 어디 에나 포함되어 있습니까? 제외 선이 단도에서 주석 처리되었으므로 엇갈림과 단검을 포함시켜야하는 것처럼 보입니다.

+0

네, 감사합니다. 한편 나는 Espresso 2.0으로 전환하고 JUnit 의존성을 제거했다. 그런 다음 대부분은 효과가 있었지만 대부분은 그렇습니다. –