In our app, we use Room database for some unit tests like below.
fun provideMyDatabase(...): MyDatabase {
return Room.inMemoryDatabaseBuilder(application, MyDatabase::class.java)
.allowMainThreadQueries()
.build()
}
When I try to run unit tests in Android Studio on my Mac I get the error:
java.lang.NoSuchFieldError: useNoBackupDirectory
These unit tests work when I run them from the command line.
I know that this is not recommended how to test database, I assume that SQLite implementation is the source of the problem, but also I am looking for some docs where I can find the exact root of the problem.
Adding the below dependency will fix the problem. Only when I use implementation, not testImplementation.
implementation("androidx.sqlite:sqlite:2.1.0")
Source about testing room: https://developer.android.com/training/data-storage/room/testing-db
My setup: Android Studio 4.1.2, OSX 11.1, Java 8, Kotlin 1.4.21
question from:
https://stackoverflow.com/questions/65898297/room-database-unit-tests-as-nosuchfielderror-usenobackupdirectory 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…