2015-06-01 11 views
21

W moim pliku build.gradle Mam zależności od bibliotek wsparcia:Dlaczego dodanie espresso-contrib spowoduje wyjątek InflateException?

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" 

Mam także zależności dla testów kawy:

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

Wszystko działa dobrze w tym momencie, ale kiedy dodać zależność dla espresso-contrib dostaję InflateException na moim 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 [email protected] 
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 "[email protected]" 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: [email protected] 
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) 

jakiś pomysł na to, dlaczego może się zdarzyć i jak mogę to naprawić?

Odpowiedz

49

Spróbuj tego w 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' 
} 
+0

Czym różni się espresso-contrib od rdzenia espresso? –

+4

espresso-contrib umożliwia testowanie klas takich jak datepicker, szuflada i recykling. Zobacz tutaj: http://developer.android.com/reference/android/support/test/espresso/contrib/package-summary.html – elcolto

+1

Rozwiązał on błąd 'No class found' dla' android.support.v7.app .AppCompatDelegateImplV14' za pomocą proguard, dzięki! – Caipivara

2

Spróbuj tego:

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

Mam ten sam problem o błędzie pompowania klasy widoku recykler, i próbowaliśmy kilka razy z różnymi kodami, wreszcie Rozwiązałem ten problem, dodając te kody w gradle projektu:

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

Po drugie, mieć pewność, że używasz widok karty i widok recykler w najnowszej wersji:

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

Następnie można uruchomić test, który ma widok recykler w to układ aktywność. To zadziała dobrze i nie powtórzy się żaden błąd.

Powiązane problemy