Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
224 views
in Technique[技术] by (71.8m points)

android - Room database + unit tests + AS = NoSuchFieldError: useNoBackupDirectory

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...