11

I have a subclass of android.support.v7.widget.RecyclerView. It works fine when I use the application and testing.

However, when I include espresso-contrib in my gradle app file I get an exception when I try to run the same tests. The app still works. The same problem occurs in both sdk versions 21 and 22, on armv emulator and device. Using an x86 emulator it segfaults instead.

Gradle

androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.0'

Exception

java.lang.IncompatibleClassChangeError: xxx.DashboardActivity$1
at dalvik.system.DexFile.defineClassNative(Native Method)
at dalvik.system.DexFile.defineClass(DexFile.java:226)
at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
at dalvik.system.DexPathList.findClass(DexPathList.java:321)
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at xxx.DashboardActivity.onCreate(DashboardActivity.java:54)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.support.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:346)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

adb logcat

I/ActivityManager( 1229): START u0 {act=android.intent.action.MAIN flg=0x14000000 cmp=xxx/.activities.DashboardActivity} from uid 10059 on display 0
V/WindowManager( 1229): addAppToken: AppWindowToken{65964e3 token=Token{3f63d512 ActivityRecord{19743c9d u0 xxx/.activities.DashboardActivity t13}}} to stack=1 task=13 at 0
D/LifecycleMonitor( 2953): Lifecycle status change: xxx.activities.DashboardActivity@281384ef in: PRE_ON_CREATE
V/WindowManager( 1229): Adding window Window{2d974c1a u0 Starting xxx} at 2 of 7 (after Window{27a98488 u0 com.android.launcher/com.android.launcher2.Launcher})
W/RecyclerView( 2953): setScrollingTouchSlop(): bad argument constant 315513600; using default value
W/art     ( 2953): Incompatible structural change detected: Structural change of android.support.v7.widget.RecyclerView$Adapter is hazardous (/data/dalvik-cache/x86/data@app@xxx-1@b
[email protected] at compile time, /data/dalvik-cache/x86/data@[email protected]@[email protected] at runtime): Virtual method count off: 26 vs 25
W/art     ( 2953): Landroid/support/v7/widget/RecyclerView$Adapter; (Compile time):
W/art     ( 2953):  Static fields:
W/art     ( 2953):  Instance fields:
W/art     ( 2953):   Z mHasStableIds
W/art     ( 2953):   Landroid/support/v7/widget/RecyclerView$AdapterDataObservable; mObservable
W/art     ( 2953):  Direct methods:
W/art     ( 2953):   <init>()V
W/art     ( 2953):  Virtual methods:
W/art     ( 2953):   bindViewHolder(Landroid/support/v7/widget/RecyclerView$ViewHolder;I)V
W/art     ( 2953):   createViewHolder(Landroid/view/ViewGroup;I)Landroid/support/v7/widget/RecyclerView$ViewHolder;
W/art     ( 2953):   getItemCount()I
W/art     ( 2953):   getItemId(I)J
W/art     ( 2953):   getItemViewType(I)I
W/art     ( 2953):   hasObservers()Z
W/art     ( 2953):   hasStableIds()Z
W/art     ( 2953):   notifyDataSetChanged()V
W/art     ( 2953):   notifyItemChanged(I)V
W/art     ( 2953):   notifyItemInserted(I)V
W/art     ( 2953):   notifyItemMoved(II)V
W/art     ( 2953):   notifyItemRangeChanged(II)V
W/art     ( 2953):   notifyItemRangeInserted(II)V
W/art     ( 2953):   notifyItemRangeRemoved(II)V
W/art     ( 2953):   notifyItemRemoved(I)V
W/art     ( 2953):   onAttachedToRecyclerView(Landroid/support/v7/widget/RecyclerView;)V
W/art     ( 2953):   onBindViewHolder(Landroid/support/v7/widget/RecyclerView$ViewHolder;I)V
W/art     ( 2953):   onCreateViewHolder(Landroid/view/ViewGroup;I)Landroid/support/v7/widget/RecyclerView$ViewHolder;
W/art     ( 2953):   onDetachedFromRecyclerView(Landroid/support/v7/widget/RecyclerView;)V
W/art     ( 2953):   onFailedToRecycleView(Landroid/support/v7/widget/RecyclerView$ViewHolder;)Z
W/art     ( 2953):   onViewAttachedToWindow(Landroid/support/v7/widget/RecyclerView$ViewHolder;)V
W/art     ( 2953):   onViewDetachedFromWindow(Landroid/support/v7/widget/RecyclerView$ViewHolder;)V
W/art     ( 2953):   onViewRecycled(Landroid/support/v7/widget/RecyclerView$ViewHolder;)V
W/art     ( 2953):   registerAdapterDataObserver(Landroid/support/v7/widget/RecyclerView$AdapterDataObserver;)V
W/art     ( 2953):   setHasStableIds(Z)V
W/art     ( 2953):   unregisterAdapterDataObserver(Landroid/support/v7/widget/RecyclerView$AdapterDataObserver;)V
W/art     ( 2953): Landroid/support/v7/widget/RecyclerView$Adapter; (Runtime):
W/art     ( 2953):  Static fields:
W/art     ( 2953):  Instance fields:
W/art     ( 2953):   Z mHasStableIds
W/art     ( 2953):   Landroid/support/v7/widget/RecyclerView$AdapterDataObservable; mObservable
W/art     ( 2953):  Direct methods:
W/art     ( 2953):   <init>()V
W/art     ( 2953):  Virtual methods:
W/art     ( 2953):   bindViewHolder(Landroid/support/v7/widget/RecyclerView$ViewHolder;I)V
W/art     ( 2953):   createViewHolder(Landroid/view/ViewGroup;I)Landroid/support/v7/widget/RecyclerView$ViewHolder;
W/art     ( 2953):   getItemCount()I
W/art     ( 2953):   getItemId(I)J
W/art     ( 2953):   getItemViewType(I)I
W/art     ( 2953):   hasObservers()Z
W/art     ( 2953):   hasStableIds()Z
W/art     ( 2953):   notifyDataSetChanged()V
W/art     ( 2953):   notifyItemChanged(I)V
W/art     ( 2953):   notifyItemInserted(I)V
W/art     ( 2953):   notifyItemMoved(II)V
W/art     ( 2953):   notifyItemRangeChanged(II)V
W/art     ( 2953):   notifyItemRangeInserted(II)V
W/art     ( 2953):   notifyItemRangeRemoved(II)V
W/art     ( 2953):   notifyItemRemoved(I)V
W/art     ( 2953):   onAttachedToRecyclerView(Landroid/support/v7/widget/RecyclerView;)V
W/art     ( 2953):   onBindViewHolder(Landroid/support/v7/widget/RecyclerView$ViewHolder;I)V
W/art     ( 2953):   onCreateViewHolder(Landroid/view/ViewGroup;I)Landroid/support/v7/widget/RecyclerView$ViewHolder;
W/art     ( 2953):   onDetachedFromRecyclerView(Landroid/support/v7/widget/RecyclerView;)V
W/art     ( 2953):   onViewAttachedToWindow(Landroid/support/v7/widget/RecyclerView$ViewHolder;)V
W/art     ( 2953):   onViewDetachedFromWindow(Landroid/support/v7/widget/RecyclerView$ViewHolder;)V
W/art     ( 2953):   onViewRecycled(Landroid/support/v7/widget/RecyclerView$ViewHolder;)V
W/art     ( 2953):   registerAdapterDataObserver(Landroid/support/v7/widget/RecyclerView$AdapterDataObserver;)V
W/art     ( 2953):   setHasStableIds(Z)V
W/art     ( 2953):   unregisterAdapterDataObserver(Landroid/support/v7/widget/RecyclerView$AdapterDataObserver;)V
I/art     ( 2953): Rejecting re-init on previously-failed class java.lang.Class<xxx.models.JSONArrayRecyclerViewAdapter>
I/art     ( 2953): Rejecting re-init on previously-failed class java.lang.Class<xxx.models.JSONArrayRecyclerViewAdapter>
I/art     ( 2953): Rejecting re-init on previously-failed class java.lang.Class<xxx.activities.DashboardActivity$1>
I/art     ( 2953): Rejecting re-init on previously-failed class java.lang.Class<xxx.activities.DashboardActivity$1>
D/AndroidRuntime( 2953): Shutting down VM
E/MonitoringInstrumentation( 2953): Exception encountered by: Thread[main,5,main]. Dumping thread state to outputs and pining for the fjords.
E/MonitoringInstrumentation( 2953): java.lang.IncompatibleClassChangeError: xxx.activities.DashboardActivity$1
E/MonitoringInstrumentation( 2953):     at dalvik.system.DexFile.defineClassNative(Native Method)
E/MonitoringInstrumentation( 2953):     at dalvik.system.DexFile.defineClass(DexFile.java:226)
E/MonitoringInstrumentation( 2953):     at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
E/MonitoringInstrumentation( 2953):     at dalvik.system.DexPathList.findClass(DexPathList.java:321)
E/MonitoringInstrumentation( 2953):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
E/MonitoringInstrumentation( 2953):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/MonitoringInstrumentation( 2953):     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
E/MonitoringInstrumentation( 2953):     at xxx.activities.DashboardActivity.onCreate(DashboardActivity.java:54)
E/MonitoringInstrumentation( 2953):     at android.app.Activity.performCreate(Activity.java:5990)
E/MonitoringInstrumentation( 2953):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
E/MonitoringInstrumentation( 2953):     at android.support.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:346)
E/MonitoringInstrumentation( 2953):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
E/MonitoringInstrumentation( 2953):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
E/MonitoringInstrumentation( 2953):     at android.app.ActivityThread.access$800(ActivityThread.java:151)
E/MonitoringInstrumentation( 2953):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
E/MonitoringInstrumentation( 2953):     at android.os.Handler.dispatchMessage(Handler.java:102)
E/MonitoringInstrumentation( 2953):     at android.os.Looper.loop(Looper.java:135)
E/MonitoringInstrumentation( 2953):     at android.app.ActivityThread.main(ActivityThread.java:5257)
E/MonitoringInstrumentation( 2953):     at java.lang.reflect.Method.invoke(Native Method)
E/MonitoringInstrumentation( 2953):     at java.lang.reflect.Method.invoke(Method.java:372)
E/MonitoringInstrumentation( 2953):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
E/MonitoringInstrumentation( 2953):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
1
  • 1
    It seems like onFailedToRecycleView(Landroid/support/v7/widget/RecyclerView$ViewHolder;) is the difference. My guess is that espresso-contrib is trying to replace a class or Interface but does not implement all the methods? I still don't know how to fix it. Commented Mar 23, 2015 at 17:29

4 Answers 4

12

Espresso dependency is out of date. Reported and will be fixed in the future. https://code.google.com/p/android-test-kit/issues/detail?id=139

Sign up to request clarification or add additional context in comments.

2 Comments

@JohnShelley I was able to get around the issue by excluding the Recyclerview module that the espresso-contrib library tries to use. androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2'){ exclude module: 'support-annotations' exclude module: 'recyclerview-v7' }
Can't edit above comment anymore, I put the wrong line above. The correct line would be: androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2'){ exclude module: 'support-annotations' exclude module: 'support-v4' exclude module: 'support-v13' exclude module: 'recyclerview-v7' }
0

please use Newest Gradle Plugin (is not a stable version)

Starting with 2.0.0 of the Android Gradle Plugin, Gradle build will fail if the main APK and the test APK use the same library (e.g. Guava) but in different versions.

To make the build succeed, just add a dependency for the newer version to the build.gradle

for example:

androidTestCompile "com.android.support:recyclerview-v7:${supportLibVersion}"

reference:

Comments

0

You can try to add that at the bottom of your gradle file (after every char)

/*
Resolves dependency versions across test and production APKs, specifically, transitive
dependencies. This is required since Espresso internally has a dependency on support-annotations.
*/
configurations.all {
    resolutionStrategy.force "com.android.support:support-annotations:$rootProject.supportLibraryVersion"
}

/*
All direct/transitive dependencies shared between your test and production APKs need to be
excluded from the test APK! This is necessary because both APKs will contain the same classes. Not
excluding these dependencies from your test configuration will result in an dex pre-verifier error
at runtime. More info in this tools bug: (https://code.google.com/p/android/issues/detail?id=192497)
*/
configurations.compile.dependencies.each { compileDependency ->
    println "Excluding compile dependency: ${compileDependency.getName()}"
    configurations.androidTestCompile.dependencies.each { androidTestCompileDependency ->
        configurations.androidTestCompile.exclude module: "${compileDependency.getName()}"
    }
}

It's from the Android-testing project on github

Source: https://github.com/googlecodelabs/android-testing/blob/master/app/build.gradle#L96

Comments

0

Maybe you forgot to add testInstrumentationRunner android.support.test.runner.AndroidJUnitRunner" in a defaultConfig{}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.