2

I'm trying to setup a dummy test to begin with my android project. However I'm unable to make my app run with espresso. Without the tests, the app is working just fine.

Here is the backtrace:

Running tests
Test running started
android.view.InflateException: Binary XML file line #30: Error inflating class android.support.design.widget.NavigationView
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:256)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at com.plop.remote.MainActivity.onCreate(MainActivity.java:62)
at android.app.Activity.performCreate(Activity.java:5953)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1128)
at android.support.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:534)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2267)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2388)
at android.app.ActivityThread.access$800(ActivityThread.java:148)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5312)
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:901)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
... 22 more
Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class android.support.design.internal.NavigationMenuView
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.support.design.internal.NavigationMenuPresenter.getMenuView(NavigationMenuPresenter.java:97)
at android.support.design.widget.NavigationView.<init>(NavigationView.java:165)
at android.support.design.widget.NavigationView.<init>(NavigationView.java:94)
... 25 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
... 31 more
Caused by: java.lang.IllegalStateException: Binary XML file line #17: Unable to find LayoutManager android.support.v7.widget.@2131296535
at android.support.v7.widget.RecyclerView.createLayoutManager(RecyclerView.java:506)
at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:444)
at android.support.design.internal.NavigationMenuView.<init>(NavigationMenuView.java:40)
at android.support.design.internal.NavigationMenuView.<init>(NavigationMenuView.java:36)
... 34 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.@2131296535" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.plop.remote.test-1/base.apk", zip file "/data/app/com.plop.remote-2/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:486)
... 37 more
Suppressed: java.lang.ClassNotFoundException: Invalid name: android.support.v7.widget.@2131296535
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)
... 39 more


java.lang.RuntimeException: Unable to start activity ComponentInfo{com.plop.remote/com.plop.remote.MainActivity}: android.view.InflateException: Binary XML file line #30: Error inflating class android.support.design.widget.NavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2314)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2388)
at android.app.ActivityThread.access$800(ActivityThread.java:148)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5312)
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:901)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
Caused by: android.view.InflateException: Binary XML file line #30: Error inflating class android.support.design.widget.NavigationView
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:256)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at com.plop.remote.MainActivity.onCreate(MainActivity.java:62)
at android.app.Activity.performCreate(Activity.java:5953)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1128)
at android.support.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:534)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2267)
... 10 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
... 22 more
Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class android.support.design.internal.NavigationMenuView
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.support.design.internal.NavigationMenuPresenter.getMenuView(NavigationMenuPresenter.java:97)
at android.support.design.widget.NavigationView.<init>(NavigationView.java:165)
at android.support.design.widget.NavigationView.<init>(NavigationView.java:94)
... 25 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
... 31 more
Caused by: java.lang.IllegalStateException: Binary XML file line #17: Unable to find LayoutManager android.support.v7.widget.@2131296535
at android.support.v7.widget.RecyclerView.createLayoutManager(RecyclerView.java:506)
at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:444)
at android.support.design.internal.NavigationMenuView.<init>(NavigationMenuView.java:40)
at android.support.design.internal.NavigationMenuView.<init>(NavigationMenuView.java:36)
... 34 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.@2131296535" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.plop.remote.test-1/base.apk", zip file "/data/app/com.plop.remote-2/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:486)
... 37 more
Suppressed: java.lang.ClassNotFoundException: Invalid name: android.support.v7.widget.@2131296535
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)
... 39 more

Test running failed: Instrumentation run failed due to 'java.lang.ClassNotFoundException'

My build.gradle:

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.plop.remote"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile project(':Box')
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:support-v4:23.1.1'
    compile 'me.neavo:volley:2014.12.09'
    compile 'com.google.code.gson:gson:2.3.1'
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.1') {
        exclude group: 'com.android.support', module: 'support-annotations'
    }
    androidTestCompile('com.android.support.test:runner:0.4.1') {
        exclude group: 'com.android.support', module: 'support-annotations'
    }
    androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.1') {
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude module: 'support-v4'
    }
}

and the XML that seems an issue

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.plop.remote.MainActivity">


    <com.plop.remote.NonSwipeableViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="50dp">

    </com.plop.remote.NonSwipeableViewPager>

    <SurfaceView
        android:layout_width="0px"
        android:layout_height="0px"
        android:visibility="gone" />

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        android:background="@color/menuBackground"
        app:headerLayout="@layout/nav_header_main"
        app:itemTextColor="@color/textColor"
        app:menu="@menu/menu_main_drawer" />

</android.support.v4.widget.DrawerLayout>

I already tried a lot a stuff in my gradle file without success so far. For instance I feel like :

Why would adding espresso-contrib cause an InflateException?

Is similar to me, except that with that gradle file my app is still running fine without the tests.

Community
  • 1
  • 1
Jeremad
  • 883
  • 2
  • 10
  • 21

2 Answers2

3

Same problem and solved with this:

androidTestCompile ("com.android.support.test.espresso:espresso-core:$espressoVersion"){
    exclude group: 'com.android.support', module: 'appcompat-v7'
    exclude group: 'com.android.support', module: 'support-v4'
    exclude module: 'recyclerview-v7'  
}
androidTestCompile ("com.android.support.test.espresso:espresso-contrib:$espressoVersion"){
    exclude group: 'com.android.support', module: 'appcompat-v7'
    exclude group: 'com.android.support', module: 'support-v4'
    exclude group: 'com.android.support', module: 'design'
    exclude module: 'recyclerview-v7'
}
Luigi Papino
  • 408
  • 3
  • 12
0

Check below configuration to check if you're not missing something

android {
    dataBinding {
        enabled = true
    }
    compileSdkVersion 23
    buildToolsVersion '23.0.2'

    defaultConfig {
        applicationId "com.piotr.example"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'

    androidTestCompile "com.android.support:support-annotations:$ASVersion"
    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: 'recyclerview-v7'
    }
    androidTestCompile 'com.android.support.test:runner:0.4.1'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile "com.android.support:appcompat-v7:$ASVersion"
    compile "com.android.support:support-v4:$ASVersion"
    compile "com.android.support:design:$ASVersion"
}

As Gradle returns no tests it may means that you forgot to include testInstrumentationRunner in your gradle configuration.

Hope it help

piotrek1543
  • 19,130
  • 7
  • 81
  • 94