我正在尝试更新我项目的 gradle
androidTestImplementation
依赖项。我正在使用 androidx.test 发布页面 的最新建议,在撰写本文时是:
// UI Testing
androidTestImplementation "androidx.arch.core:core-testing:2.1.0"
androidTestImplementation "androidx.test.espresso:espresso-contrib:3.5.0"
androidTestImplementation "androidx.test.espresso:espresso-core:3.5.0"
androidTestImplementation "androidx.test.espresso:espresso-intents:3.5.0"
androidTestImplementation "androidx.test.espresso:espresso-web:3.5.0"
androidTestImplementation "androidx.test.ext:junit-ktx:1.1.4"
androidTestImplementation "androidx.test:core-ktx:1.5.0"
androidTestImplementation "androidx.test:monitor:1.6.0"
androidTestImplementation "androidx.test:rules:1.5.0"
androidTestImplementation "androidx.test:runner:1.5.0"
我的 Espresso 测试过去可以正常启动,但尽管现在测试编译正常但启动挂起,我看到:
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/test/platform/io/PlatformTestStorageRegistry
这是堆栈跟踪:
15:23:14.293 AndroidRuntime E FATAL EXCEPTION: main
Process: <my bundle id>, PID: <pid>
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/test/platform/io/PlatformTestStorageRegistry;
at androidx.test.internal.runner.RunnerArgs$Builder.<init>(RunnerArgs.java:248)
at androidx.test.runner.AndroidJUnitRunner.parseRunnerArgs(AndroidJUnitRunner.java:393)
at androidx.test.runner.AndroidJUnitRunner.onCreate(AndroidJUnitRunner.java:302)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6726)
at android.app.ActivityThread.access$1500(ActivityThread.java:256)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2090)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7842)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
...
我发现这个问题听起来很相似:https://github.com/android/android-test/issues/1315所以我在我的
build.gradle
中尝试过这个,但没有任何区别。
androidTestImplementation("androidx.test:monitor:1.6.0") {
transitive = false
}
我尝试过清理项目并使缓存无效。
你如何调试这种问题?什么是兼容的测试包?
作为参考,我遇到了同样的问题,对我来说诀窍是将此监视器依赖项特别添加为
debugImplementation
到 build.gradle
而不是使用 androidTestImplementation
.
debugImplementation "androidx.test:monitor:1.6.0"
来源:github