简体   繁体   English

java.lang.NoClassDefFoundError: androidx/sqlite/db/SupportSQLiteQuery 在昨天工作的单元测试中

[英]java.lang.NoClassDefFoundError: androidx/sqlite/db/SupportSQLiteQuery in unit test that worked yesterday

The answer to this question is not "Android unit tests cannot access Android stack modules such as the Room database because on your desktop they are all stubbed out."这个问题的答案不是“Android 单元测试无法访问 Android 堆栈模块,例如 Room 数据库,因为在您的桌面上它们都被删除了。”

I had a bunch of unit tests that tested static methods that happened to be inside a Dao class - call it FooDao .我有一堆单元测试来测试 static 方法,这些方法恰好位于 Dao class 内 - 称之为FooDao They all passed for a year until today, when they stopped passing when the Android Studio editor calls them.它们都过了一年,直到今天,当Android Studio编辑器调用它们时,它们停止了传递。 They still pass when the command line tests call them, but the editor reports:当命令行测试调用它们时它们仍然通过,但编辑器报告:

java.lang.NoClassDefFoundError: androidx/sqlite/db/SupportSQLiteQuery

This happens when the unit test gets to FooDao.innocentStaticMethod() .当单元测试到达FooDao.innocentStaticMethod()时,就会发生这种情况。 Like I said, accessing the FooDao class without invoking any of its real Room methods formerly worked in unit tests.就像我说的,访问FooDao class 而不调用以前在单元测试中工作的任何真实 Room 方法。

The long-term fix is to refactor my code so FooDao only contains real Room calls.长期的解决办法是重构我的代码,让FooDao只包含真正的 Room 调用。 But why did Android Studio's test runner suddenly stop working?但是为什么Android Studio的test runner突然停止工作了呢? The version is Android Studio 4.2 RC 1, built on March 23, 2021. And targetSdkVersion 30 .版本为 Android Studio 4.2 RC 1,构建于 2021 年 3 月 23 日targetSdkVersion 30

Switching from androidx.room:room-runtime:2.2.6 and compiler to 2.3.0 did it, on April 22th.androidx.room:room-runtime:2.2.6和编译器切换到2.3.0是在 4 月 22 日完成的。

In app/build.gradle:在 app/build.gradle 中:

implementation 'androidx.room:room-runtime:2.2.6'
annotationProcessor 'androidx.room:room-compiler:2.2.6'

So while I leave a band-aid on the problem until the next time we need to upgrade my mighty FooDao , could someone ping Android central about this?因此,虽然我在问题上留下了创可贴,直到下次我们需要升级我强大FooDao时,有人可以就此对 Android 中心进行 ping 操作吗? ktx ktx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM