使用Lollipop下的设备在Espresso中测试失败(失败:由于'java.lang.IllegalAccessError'导致仪器运行失败)

时间:2015-11-17 10:51:15

标签: android testing spoon multidex expresso

我正在尝试在一个multidex项目中使用Spoon进行expresso测试。在使用Lollipop或Marshmallow的设备/ VM中测试运行没有问题,但它们在Lollipop设备下无法正常工作。

在stackoverflow中还有一些关于这个问题的问题,并且所有解决方案都讨论了在Gradle的依赖项配置中避免重复库的问题,但我找不到它们,也没有任何其他问题。

这是make ./gradlew -q:project:dependencies

的结果
_debugAndroidTestApk - ## Internal use, do not manually configure ##
+--- com.android.support.test:runner:0.4.1
|    +--- com.android.support.test:exposed-instrumentation-api-publish:0.4.1
|    \--- junit:junit:4.12
|         \--- org.hamcrest:hamcrest-core:1.3
+--- com.android.support.test:rules:0.4.1
|    \--- com.android.support.test:runner:0.4.1 (*)
+--- com.android.support.test.espresso:espresso-contrib:2.2.1
|    +--- com.android.support.test.espresso:espresso-core:2.2.1
|    |    +--- com.squareup:javawriter:2.1.1
|    |    +--- com.android.support.test:runner:0.4.1 (*)
|    |    +--- com.android.support.test:rules:0.4.1 (*)
|    |    +--- org.hamcrest:hamcrest-library:1.3
|    |    |    \--- org.hamcrest:hamcrest-core:1.3
|    |    +--- org.hamcrest:hamcrest-integration:1.3
|    |    |    \--- org.hamcrest:hamcrest-library:1.3 (*)
|    |    +--- com.google.code.findbugs:jsr305:2.0.1
|    |    +--- javax.annotation:javax.annotation-api:1.2
|    |    +--- com.android.support.test.espresso:espresso-idling-resource:2.2.1
|    |    \--- javax.inject:javax.inject:1
|    \--- com.google.android.apps.common.testing.accessibility.framework:accessibility-test-framework:2.0
|         \--- org.hamcrest:hamcrest-core:1.3
+--- com.android.support.test.espresso:espresso-core:2.2.1 (*)
+--- com.android.support.test.espresso:espresso-intents:2.2.1
|    \--- com.android.support.test.espresso:espresso-core:2.2.1 (*)
+--- com.android.support:multidex-instrumentation:1.0.1
+--- com.squareup.spoon:spoon-client:1.2.0
\--- project :multidextest
 +--- com.android.support:multidex:1.0.1
 \--- com.android.support.test:runner:0.4.1 (*)

这些是我们的依赖:

dependencies {
    compile project(':MemorizingTrustManager')
    compile project(':widgets')
    compile fileTree(dir: 'libs')
    compile 'com.android.support:multidex:1.0.1'
    compile "org.igniterealtime.smack:smack-android-extensions:4.1.3"
    compile "org.igniterealtime.smack:smack-experimental:4.1.3"
    compile "org.igniterealtime.smack:smack-tcp:4.1.3"
    compile 'com.android.support:support-v4:23.0.1'
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
    compile 'com.android.support:cardview-v7:23.0.1'
    compile 'com.android.support:recyclerview-v7:23.0.1'
    compile 'com.jakewharton:butterknife:6.1.0'
    compile 'com.squareup:otto:1.3.7'
    compile 'com.squareup.okhttp:okhttp:2.4.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.4.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'uk.co.chrisjenx:calligraphy:2.1.0'
    compile 'com.google.dagger:dagger:2.0.1'
    apt 'com.google.dagger:dagger-compiler:2.0.1'
    provided 'org.glassfish:javax.annotation:10.0-b28'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.github.pedrovgs:renderers:2.0.3'
    compile 'com.getbase:floatingactionbutton:1.10.0'
    compile 'fr.avianey.com.viewpagerindicator:library:2.4.1@aar'
    compile 'com.google.android.gms:play-services-analytics:8.1.0'
    compile 'com.google.android.gms:play-services-gcm:8.1.0'
    compile "com.mixpanel.android:mixpanel-android:4.6.4"
    compile 'org.apmem.tools:layouts:1.8@aar'
    compile('com.crashlytics.sdk.android:crashlytics:2.3.2@aar') {
        transitive = true;
    }
    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-all:1.10.19'
    testCompile 'org.hamcrest:hamcrest-all:1.3'
    androidTestCompile ('com.android.support.test:runner:0.4.1') {
        exclude module: 'support-annotations'
    }
    androidTestCompile ('com.android.support.test:rules:0.4.1') {
        exclude module: 'support-annotations'
    }
    androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.1') {
        exclude module: 'support-annotations'
        exclude module: 'support-v4'
        exclude module: 'support-v13'
        exclude module: 'recyclerview-v7'
        exclude group: 'javax.inject'
    }
    androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2.1') {
        exclude module: 'support-annotations'
        exclude group: 'javax.inject'
    }
    androidTestCompile ('com.android.support.test.espresso:espresso-intents:2.2.1') {
        exclude module: 'support-annotations'
    }
    androidTestCompile('com.android.support:multidex-instrumentation:1.0.1') {
        exclude group: 'com.android.support', module: 'multidex'
    }
    androidTestCompile "com.squareup.spoon:spoon-client:1.2.0"
    androidTestCompile project(':multidextest')
}

最后是带有问题的堆栈跟踪:

11:18:24 D/Device: Uploading file onto device 'emulator-5554'
2015-11-17 11:18:49 [SDR.run] About to actually run tests for [emulator-5554]
11:18:49 I/RemoteAndroidTest: Running am instrument -w -r  -e class com.redbooth.newredbooth.presentation.tests.collaboration.dashboard.DashboardActivityTest com.project.debug.test/com.project.multidextest.MultidexAndroidJUnitRunner on Nexus_One_API_15 [emulator-5554]
11:18:49 I/InstrumentationResultParser: test run failed: 'Instrumentation run failed due to 'java.lang.IllegalAccessError''
2015-11-17 11:18:49 [STRL.testRunStarted] testCount=0 runName=com.project.debug.test
2015-11-17 11:18:49 [STRL.testRunFailed] errorMessage=Instrumentation run failed due to 'java.lang.IllegalAccessError'
2015-11-17 11:18:49 [STRL.testRunEnded] elapsedTime=0
11:18:49 I/XmlResultReporter: XML test result file generated at /Users/disaster/Repositorios/Project/android/project/build/custom-report-dir/debug/junit-reports/emulator-5554.xml. Total tests 0, 
2015-11-17 11:18:50 [SDR.run] About to grab screenshots and prepare output for [emulator-5554]
2015-11-17 11:18:50 [SDR.pullScreenshotsFromDevice] Internal path is /data/data/com.project.debug/app_spoon-screenshots
2015-11-17 11:18:50 [SDR.pullScreenshotsFromDevice] External path is /mnt/sdcard/app_spoon-screenshots
2015-11-17 11:18:50 [SDR.pullScreenshotsFromDevice] Pulling screenshots from external dir on [emulator-5554]
2015-11-17 11:18:50 [SDR.pullScreenshotsFromDevice] Pulling screenshots from internal dir on [emulator-5554]
2015-11-17 11:18:50 [SDR.pullScreenshotsFromDevice] Done pulling screenshots from [emulator-5554]
2015-11-17 11:18:50 [SDR.run] Moving screenshots to the image folder on [emulator-5554]
2015-11-17 11:18:50 [SDR.run] Generating animated gifs for [emulator-5554]
2015-11-17 11:18:50 [SDR.run] Done running for [emulator-5554]
2015-11-17 11:18:50 [SR.runTests] [emulator-5554] Execution done.
:project:spoonDebugAndroidTest FAILED

1 个答案:

答案 0 :(得分:0)

最后,我发现了问题><。

AndroidJUnitRunner与Multidex兼容,因此无需创建替代Runner,因为您可以阅读以下消息:https://plus.google.com/+OleksandrKucherenko/posts/i7qZdVEy3Ue

另一方面,我有一个带有新跑步者和一些测试的模块,但这并不是必需的。我删除了模块并再次将testInstrumentationRunner配置为 testInstrumentationRunner' android.support.test.runner.AndroidJUnitRunner'问题是固定的。!