java.lang.NoClassDefFoundError: android.support.test.espresso.matcher.ViewMatchers

725 views
Skip to first unread message

X_Jay_X

unread,
Sep 16, 2015, 7:42:14 PM9/16/15
to Android Testing Support Library
Hi, using the following line of code 
  • onView(withId(R.id.my_Button)).perform(ViewActions.click());
I have all the imports I need, no errors there, but when I launch the app and the line above is hit I get the following error:
  • java.lang.NoClassDefFoundError: android.support.test.espresso.matcher.ViewMatchers$12   (Set up is done and project builds properly, Why of this class not found error?)
Our app uses multiple modules. Any feedback is appreciated. 

Stephan Linzner

unread,
Sep 18, 2015, 12:39:26 PM9/18/15
to Android Testing Support Library
Can you please post you build.gradle file here?

X_Jay_X

unread,
Sep 18, 2015, 2:15:24 PM9/18/15
to Android Testing Support Library
Hi,  I actually got passed this as it was an build.gradle set up.  However, now I run into the following error: 

java.lang.IncompatibleClassChangeError: Class 'android.widget.TextView' does not implement interface 'org.hamcrest.Description' in call to 'org.hamcrest.Description org.hamcrest.Description.appendText(java.lang.String)' (declaration of 'java.lang.reflect.ArtMethod' appears in /system/framework/core-libart.jar)

When I try to use,  onView(withText('sampletest'))

X_Jay_X

unread,
Sep 18, 2015, 3:21:57 PM9/18/15
to Android Testing Support Library
Gradle File looks like this:

apply plugin: 'com.android.application'

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
    enforceUniquePackageName false

    defaultConfig {
        applicationId "com.app.main"
        minSdkVersion 15
        // targetSdkVersion MUST be 21 since 22 causes crash AF-4259 one some devices.
        targetSdkVersion 21
        multiDexEnabled true

        testApplicationId "com.app.test"
        //testInstrumentationRunner "com.cheerfulinc.app.tests.FGInstrumentationTestRunner"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    dexOptions {
        incremental true
        javaMaxHeapSize "4g"
        preDexLibraries = false
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'LICENSE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/DEPENDENCIES'
    }

    signingConfigs {
        debug {
            storeFile file("../debug.keystore")
        }
        release {
            storeFile file("keystore.ks")
            storePassword "app"
            keyAlias "app"
            keyPassword "app"
        }
    }
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src', '../hockeyapp/src', 'src/main/java', 'src/main/androidTest', 'src/main/java/', 'androidTest/java']
            res.srcDirs = ['res']
            jniLibs.srcDirs = ['../hockeyapp/libs']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['../app-renderer/renderer/libs', '../hockeyapp/libs']
        }
        androidTest {
            manifest.srcFile '../app/AndroidManifest.xml'
            java.srcDirs = ['../app/src', '../app-automation/src']
            res.srcDirs = ['../app/res', '../app-automation/res']
            assets.srcDirs = ['../app/assets', '../app-automation/assets']
        }


    }

    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }

    productFlavors {
        x86 {}
        armv7 {}
    }
}

dependencies {

    // support libraries
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:cardview-v7:22.2.0'
    compile 'com.android.support:recyclerview-v7:22.2.0'
    compile 'com.android.support:design:22.2.1'


    // App dependencies for espresso
    compile 'org.hamcrest:hamcrest-library:1.3'
    compile 'com.android.support:support-annotations:23.0.1'
    compile 'com.google.guava:guava:18.0'

    androidTestCompile 'org.hamcrest:hamcrest-library:1.3'

    androidTestCompile('com.android.support:multidex-instrumentation:1.0.0') {
        // multidex is already a compile dependency.
        exclude group: 'com.android.support', module: 'multidex'
    }

    androidTestCompile 'junit:junit:4.12'

    // test deps
    androidTestCompile files('../app/libs/dexmaker-1.1.jar')
    androidTestCompile files('../app/libs/dexmaker-mockito-1.1.jar')
    androidTestCompile files('../app/libs/mockito-all-1.9.5.jar')

    androidTestCompile files('../app-automation/libs/android-junit-report-1.5.8.jar')
    androidTestCompile files('../app-automation/libs/commons-lang3-3.4.jar')
    androidTestCompile files('../app-automation/libs/jsch-0.1.51.jar')
    androidTestCompile files('../app-automation/libs/robotium-solo-5.3.1.jar')


    androidTestCompile 'com.android.support.test:runner:0.4'

    androidTestCompile 'com.android.support.test:rules:0.4'

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

    // add this for intent mocking support
    androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2'
    // add this for webview testing support
    androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2'


}


Message has been deleted

vnsq...@gmail.com

unread,
Jan 25, 2016, 11:29:37 AM1/25/16
to Android Testing Support Library
Hi X_Jay_X,

Could you please post the work around on build.gradle setup for "java.lang.NoClassDefFoundError: android.support.test.espresso.matcher.ViewMatchers$12" issue?
I got the same issue and also guess the error come from gradle because the project build successfully but only espresso test modules stuck at it.

Thanks
Reply all
Reply to author
Forward
0 new messages