該應用程序包含一個簡短顯示的啓動畫面,該活動正在使用測試測試,使用IdlingResource進行測試,以便測試知道閃屏何時關閉。問題是,SplashActivity投上運行的API 19設備測試過程中是什麼樣子的依賴相關的例外:IllegalAccessError與CountingIdlingResource
import android.support.test.espresso.idling.CountingIdlingResource;
...
private CountingIdlingResource espressoTestIdlingResource =
new CountingIdlingResource("Splash_Delay"); // <-- Exception here line 22
...
應用/的build.gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.google.code.findbugs'
exclude module: 'espresso-idling-resource'
exclude group: "javax.inject"
})
compile 'com.android.support.test.espresso:espresso-idling-resource:2.2.2'
compile 'com.google.dagger:dagger:2.10'
annotationProcessor 'com.google.dagger:dagger-compiler:2.10'
compile 'com.google.dagger:dagger-android:2.10'
compile 'com.google.dagger:dagger-android-support:2.10'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.10'
compile "com.android.support:appcompat-v7:$supportLibraryVersion"
compile "com.android.support:design:$supportLibraryVersion"
compile "com.android.support.constraint:constraint-layout:1.0.2"
compile "com.jakewharton.timber:timber:4.5.1"
compile "com.squareup.phrase:phrase:1.1.0"
compile "com.squareup.retrofit2:retrofit:2.2.0"
compile "com.squareup.retrofit2:converter-gson:2.2.0"
compile "com.squareup.okhttp3:logging-interceptor:3.7.0"
compile 'net.danlew:android.joda:2.9.9'
testCompile 'junit:junit:4.12'
compile 'com.google.firebase:firebase-crash:10.2.4'
androidTestCompile 'junit:junit:4.12'
}
例外:
java.lang.IllegalAccessError
java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
at com.myapp.android.ui.splash.SplashActivity.<init>(SplashActivity.java:22)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1208)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2101)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.accessX800(ActivityThread.java:135)
at android.app.ActivityThreadXH.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInitXMethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Firebase測試實驗室中的API級別19 Nexus 4物理設備發生異常。它不會在我們正在測試的任何其他平臺上發生,包括本地API 19模擬的Nexus S.
我明白意思是存在模糊/重複(傳遞)依賴性的異常,但在gradlew依賴關係中看不到任何其他平臺,只有Espresso Idling Resources v2.2.2。因爲CountingIdlingResource在Activity中被引用,所以依賴是「編譯」而不是「androidTestCompile」。
如何識別原因並解決?
UPDATE:異常也與API 19上發生Nexus 5和Nexus 7.下面是與所述空轉資源庫「./gradlew依賴性」的輸出的部分:
_debugApk - ## Internal use, do not manually configure ##
+--- com.android.support.test.espresso:espresso-idling-resource:2.2.2
+--- com.google.dagger:dagger:2.10
...
_debugCompile - ## Internal use, do not manually configure ##
+--- com.android.support.test.espresso:espresso-idling-resource:2.2.2
+--- com.google.dagger:dagger:2.10
...
_releaseApk - ## Internal use, do not manually configure ##
+--- com.android.support.test.espresso:espresso-idling-resource:2.2.2
+--- com.google.dagger:dagger:2.10
...
_releaseCompile - ## Internal use, do not manually configure ##
+--- com.android.support.test.espresso:espresso-idling-resource:2.2.2
+--- com.google.dagger:dagger:2.10
...
compile - Classpath for compiling the main sources.
+--- com.android.support.test.espresso:espresso-idling-resource:2.2.2
+--- com.google.dagger:dagger:2.10
這可能是愚蠢的建議,但是您在物理設備上運行測試之前是否禁用了動畫? –
測試在BuddyBuild CI上運行,他們使用Firebase測試實驗室進行設備測試,所以我期望關閉動畫,這看起來很有可能,因爲我知道許多用於在先前CI服務器上失敗的測試,直到我們關閉它們。但是我不確定動畫是什麼問題,因爲應用程序似乎在尋找與閒置資源相關的意外類,而不是在測試驗證失敗的更常見的意義上失敗。 –
好吧,我明白了。我想上次我看到這種類似的問題是因爲espresso庫是用老版本的Android支持庫編譯的,而我使用了我的項目中的最後一個。我再一次在Android 4.4設備上觀察到了這一點。所以,最後只有這個解決方法適用於我 - http://stackoverflow.com/a/28862902/2241008。希望它也能幫助你。 –