25

In my build.gradle file I have the support library dependencies:

compile "com.android.support:appcompat-v7:22.2.0"
compile "com.android.support:recyclerview-v7:22.2.0"
compile "com.android.support:design:22.2.0"

I also have dependencies for espresso tests:

androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2'

Everything runs fine at this point, but when I add the dependency for espresso-contrib I get an InflateException on my RecyclerView

android.view.InflateException: Binary XML file line #33: Error inflating class android.support.v7.widget.RecyclerView
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
...
Caused by: java.lang.IllegalStateException: Binary XML file line #33: Unable to find LayoutManager android.support.v7.widget.@2131296518
at android.support.v7.widget.RecyclerView.createLayoutManager(RecyclerView.java:500)
at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:438)
at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:404)
...
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.@2131296518" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.myapp.debug.test-1/base.apk", zip file "/data/app/com.myapp.debug-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.support.v7.widget.RecyclerView.createLayoutManager(RecyclerView.java:480)
...
Suppressed: java.lang.ClassNotFoundException: Invalid name: android.support.v7.widget.@2131296518
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)

Any idea on why this might be happening and how I can fix it?

3 Answers 3

53

Try this in your build.gradle:

androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2'){
    exclude group: 'com.android.support', module: 'appcompat-v7'
    exclude group: 'com.android.support', module: 'support-v4'
    exclude module: 'recyclerview-v7'
}
7
  • What's the difference between espresso-contrib and espresso-core? Jun 15, 2015 at 4:37
  • 4
    espresso-contrib gives you capabilities to test classes like datepicker, drawerlayout and recyclerview. See here: developer.android.com/reference/android/support/test/espresso/…
    – elcolto
    Jun 15, 2015 at 13:46
  • 1
    It solved an error No class found for android.support.v7.app.AppCompatDelegateImplV14 using proguard, thanks! Jul 14, 2015 at 0:03
  • This should be accepted as the correct answer! Thanks a lot! Dec 21, 2015 at 22:41
  • I had a freeze while starting the app. and now it is gone. thanks Jan 12, 2016 at 9:56
7

I have the same problem about error inflating class recycler view, and tried several times with various codes, finally i resolved this problem with added these codes in project gradle:

 androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1'
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2.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: 'recyclerview-v7'
}

Secondly, you have to make sure you're using card view and recycler view in the latest version:

compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'

Then you can run your test which has recycler view in it's activity layout. It'll work fine and no error happens again.

3

Try this:

// Testing dependencies
androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1'
    androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.1') {
        exclude group: 'com.android.support', module: 'appcompat'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude module: 'support-annotations'
        exclude module: 'recyclerview-v7'
    }

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.