我正在尝试在 multidex 项目中使用 Spoon 运行 expresso 测试。测试在带有 Lollipop 或 Marshmallow 的设备/VM 中运行没有问题,但它们在 Lollipop 设备下不起作用。
在 stackoverflow 中还有一些关于这个问题的其他问题,所有解决方案都谈到避免在 Gradle 的依赖项配置中重复库,但我找不到它们,也找不到任何其他问题。
这是 make a ./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