Wednesday, May 24, 2017

IllegalAccessError with CountingIdlingResource

Leave a Comment

The app contains a splash screen that displays briefly, and that activity is being tested with an instrumented test, using an IdlingResource so the test knows when the splash screen closes. The problem is that SplashActivity throws what looks like a dependency-related exception during test on devices running API 19:

import android.support.test.espresso.idling.CountingIdlingResource; ... private CountingIdlingResource espressoTestIdlingResource = new CountingIdlingResource("Splash_Delay"); // <-- Exception here line 22 ... 

app/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' } 

Exception:

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) 

The exception occurs on an API level 19 Nexus 4 physical device in Firebase Test Lab. It does not occur on any other platforms we are testing on, including a local API 19 emulated Nexus S.

I understood the exception to mean there are ambiguous/duplicate (transitive) dependencies, but I cannot see any in gradlew dependencies, only Espresso Idling Resources v2.2.2. The dependency is "compile" not "androidTestCompile" as CountingIdlingResource is referenced in the Activity.

How do I identify the cause and resolve it?

UPDATE: The exception also occurs with API 19 on a Nexus 5 and Nexus 7. Here are the parts of the output of "./gradlew dependencies" relating to the idling resource library:

_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 

1 Answers

Answers 1

As I understand Google Samples the dependency:

com.android.support.test.espresso:espresso-idling-resource:2.2.2 

is only needed when you are implementing custom IdlingResource. Even in IdlingResourceSample README there is a sentence:

Consider using the CountingIdlingResource class from the espresso-contrib package

And as I understand your code you are trying to use CountingIdlingResource from espresso-contrib package, so try to organise your test dependencies as written in other Google sample.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment