contrib会导致InflateException

contrib会导致InflateException

本文介绍了为什么添加espresso-contrib会导致InflateException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的build.gradle文件中,我具有支持库依赖项:

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'

此时一切正常,但是当我添加espresso-contrib的依赖项时,我在RecyclerView

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?

推荐答案

在build.gradle中尝试:

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

这篇关于为什么添加espresso-contrib会导致InflateException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 20:18