No JSBridge error when running Android tests

Viewed 1806

Intermittently when running androidTests, I get a message 'Test running startedFinish Empty test suite.' and the stacktrace when this happens is given below.

I run the tests using ADB over Wi-Fi as my device connects to another device using the USB. I made sure that the device is still connected when I noticed this exception. Just to be clear, my app is a native app and there is no webview.

I/MonitoringInstrumentation: No JSBridge.
        java.lang.ClassNotFoundException: android.support.test.espresso.web.bridge.JavaScriptBridge
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:251)
        at java.lang.Class.forName(Class.java:216)
        at android.support.test.runner.MonitoringInstrumentation.tryLoadingJsBridge(MonitoringInstrumentation.java:621)
        at android.support.test.runner.MonitoringInstrumentation.access$100(MonitoringInstrumentation.java:90)
        at android.support.test.runner.MonitoringInstrumentation$4.run(MonitoringInstrumentation.java:232)
        at android.app.Instrumentation$SyncRunnable.run(Instrumentation.java:1747)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:146)
        at android.app.ActivityThread.main(ActivityThread.java:5602)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
        at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NoClassDefFoundError: android/support/test/espresso/web/bridge/JavaScriptBridge
        at java.lang.Class.classForName(Native Method) 
        at java.lang.Class.forName(Class.java:251) 
        at java.lang.Class.forName(Class.java:216) 
        at android.support.test.runner.MonitoringInstrumentation.tryLoadingJsBridge(MonitoringInstrumentation.java:621) 
        at android.support.test.runner.MonitoringInstrumentation.access$100(MonitoringInstrumentation.java:90) 
        at android.support.test.runner.MonitoringInstrumentation$4.run(MonitoringInstrumentation.java:232) 
        at android.app.Instrumentation$SyncRunnable.run(Instrumentation.java:1747) 
        at android.os.Handler.handleCallback(Handler.java:733) 
        at android.os.Handler.dispatchMessage(Handler.java:95) 
        at android.os.Looper.loop(Looper.java:146) 
        at android.app.ActivityThread.main(ActivityThread.java:5602) 
        at java.lang.reflect.Method.invokeNative(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:515) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) 
        at dalvik.system.NativeStart.main(Native Method) 
     Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.test.espresso.web.bridge.JavaScriptBridge" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/my.app.unittest.testapp.test-18.apk", zip file "/data/app/my.app.unittest.testapp-3.apk"],nativeLibraryDirectories=[/data/app-lib/my.app.unittest.testapp.test-18, /data/app-lib/my.app.unittest.testapp-3, /vendor/lib, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
        at java.lang.Class.classForName(Native Method) 
        at java.lang.Class.forName(Class.java:251) 
        at java.lang.Class.forName(Class.java:216) 
        at android.support.test.runner.MonitoringInstrumentation.tryLoadingJsBridge(MonitoringInstrumentation.java:621) 
        at android.support.test.runner.MonitoringInstrumentation.access$100(MonitoringInstrumentation.java:90) 
        at android.support.test.runner.MonitoringInstrumentation$4.run(MonitoringInstrumentation.java:232) 
        at android.app.Instrumentation$SyncRunnable.run(Instrumentation.java:1747) 
        at android.os.Handler.handleCallback(Handler.java:733) 
        at android.os.Handler.dispatchMessage(Handler.java:95) 
        at android.os.Looper.loop(Looper.java:146) 
        at android.app.ActivityThread.main(ActivityThread.java:5602) 
        at java.lang.reflect.Method.invokeNative(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:515) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) 
        at dalvik.system.NativeStart.main(Native Method) 
        03-10 13:24:27.993 32423-32437/my.app.unittest.testapp I/MonitoringInstrumentation: waitForActivitiesToComplete() took: 0ms
        03-10 13:24:27.993 32423-32423/my.app.unittest.testapp I/MonitoringInstrumentation: Activities that are still in CREATED to STOPPED: 0
        03-10 13:24:28.213 580-591/? I/ActivityManager: Killing 32423:my.app.unittest.testapp/u0a233 (adj 0): stop my.app.unittest.testapp

Here is my build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "my.app.unittest.testapp"
        minSdkVersion 18
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"

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

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    testCompile 'junit:junit:4.12'
    androidTestCompile 'com.android.support:support-annotations:23.1.1'

    androidTestCompile 'com.android.support.test:runner:0.4'
    // Set this dependency to use JUnit 4 rules
    androidTestCompile 'com.android.support.test:rules:0.4'
    // Set this dependency to build and run Espresso tests
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
    // UiAutomator Testing
    androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
    androidTestCompile 'org.hamcrest:hamcrest-integration:1.3'

    compile project(':android-sdk')
}
1 Answers
Related