gradle 为什么Espresso测试无法使用NoClassDefFoundError PlatformTestStorageRegistry启动?

46qrfjad  于 2023-04-30  发布在  其他
关注(0)|答案(1)|浏览(103)

我正在尝试更新项目的gradle androidTestImplementation依赖项。我使用的是androidx.test releases page的最新建议,在撰写本文时是:

// 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
}

我尝试过清理项目和无效缓存。
如何调试这类问题?什么是兼容的测试包集?

kgqe7b3p

kgqe7b3p1#

作为参考,我也遇到了同样的问题,对我来说,诀窍是将这个监视器依赖项专门作为debugImplementation添加到build.gradle,而不是使用androidTestImplementation

debugImplementation "androidx.test:monitor:1.6.0"

来源:github

相关问题