【问题标题】:Instrumentation run failed due to 'java.lang.NoClassDefFoundError' on Android Marshmallow由于 Android Marshmallow 上的“java.lang.NoClassDefFoundError”,检测运行失败
【发布时间】:2018-06-08 20:34:30
【问题描述】:

我正在尝试在 Android 6.0 (API 23) 设备(模拟器和物理设备)上运行 gradle Task :app:connectedDevDebugAndroidTest,但遇到了错误:

> Task :app:processDevDebugGoogleServices
Parsing json file: /Users/<name>/Projects/mobile-app-android/app/google-services.json
Starting 0 tests on Nexus_4_API_23(AVD) - 6.0
Tests on Nexus_4_API_23(AVD) - 6.0 failed: Instrumentation run failed due to 'java.lang.NoClassDefFoundError'

com.android.builder.testing.ConnectedDevice > No tests found.[Nexus_4_API_23(AVD) - 6.0] FAILED 
No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack @Test annotations).

> Task :app:connectedDevDebugAndroidTest FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:connectedDevDebugAndroidTest'.
> There were failing tests. See the report at: file:///Users/<name>/Projects/mobile-app-android/app/build/reports/androidTests/connected/flavors/DEV/index.html

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

我已尝试找出问题的不同原因。只有在终端中运行./gradlew connectedDevDebugAndroidTest(仪器测试)时才会弹出此错误。我最近升级了一些测试库,在app/build.gradle:

testImplementation 'junit:junit:4.12'
testImplementation 'org.robolectric:robolectric:3.7.1'
testImplementation 'org.robolectric:shadows-support-v4:3.0'
testImplementation ('com.squareup.assertj:assertj-android:1.1.1') {
    exclude group: 'com.android.support', module: 'support-annotations'
}
testImplementation 'org.mockito:mockito-core:2.16.0'

androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation ('com.android.support.test.espresso:espresso-contrib:2.2.2') {
    exclude group: 'com.android.support', module: 'appcompat'
    exclude group: 'com.android.support', module: 'support-v4'
    exclude group: 'com.android.support', module: 'recyclerview-v7'
}
androidTestImplementation 'com.google.guava:guava:23.0'  // Needed for EspressoTestRule

androidTestImplementation 'org.mockito:mockito-android:2.16.0'
androidTestImplementation 'com.github.fabioCollini:DaggerMock:0.8.4'
androidTestImplementation 'com.github.andrzejchm.RESTMock:android:0.1.3'
androidTestImplementation('com.squareup.okhttp3:mockwebserver:3.8.1') {
    exclude module: 'bcprov-jdk15on'
    exclude module: 'okhttp'  // See: https://github.com/square/okhttp/issues/679
}

androidTestImplementation 'org.skyscreamer:jsonassert:1.4.0'

我怀疑mockitoespresso 的最新版本中的某些东西破坏了东西,但我不确定。

【问题讨论】:

    标签: android android-gradle-plugin mockito android-6.0-marshmallow android-espresso


    【解决方案1】:

    对于特定设备,我偶尔会收到“未找到测试”错误,清理项目、关闭 Android Studio 并重新启动它似乎可以解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-09
      • 1970-01-01
      • 2016-01-22
      相关资源
      最近更新 更多