architecture-samples icon indicating copy to clipboard operation
architecture-samples copied to clipboard

[todo-mvp] not find the class RoomDatabase

Open RamboPan opened this issue 7 years ago • 1 comments

When I rebuild the project and run it. It taost not find the class.

Not find the class : Database
Not find the class : RoomDatabase

The package seems not exist.?

android.arch.persistence.room

I click Poject ---> External Library ---> and find some maybe concern with package Room.

android.arch.persistence.room:migration
android.arch.persistence.room:testing
android.arch.persistence.db
android.arch.persistence.db-framwork

I check out all the package but find no package I look for. and no concerns class.

Maybe some class lost or I open in a wrong posture?

RamboPan avatar Aug 19 '18 04:08 RamboPan

Why This Happens The todo-mvp sample predates the stable androidx.room packages and originally used:

android.arch.persistence.room:runtime But Room classes like RoomDatabase live in the android.arch.persistence.room namespace or androidx.room (in newer versions).

Fix: Add Missing Room Dependencies If you're using pre-AndroidX (android.arch.*) Room, add this to your build.gradle:

dependencies { implementation "android.arch.persistence.room:runtime:1.1.1" annotationProcessor "android.arch.persistence.room:compiler:1.1.1" } Or for AndroidX (recommended for new projects):

dependencies { def room_version = "2.6.1"

implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"

} If you use Kotlin:

kapt "androidx.room:room-compiler:$room_version" Make sure your gradle.properties enables Jetpack's AndroidX support:

android.useAndroidX=true android.enableJetifier=true After Fixing Dependencies Sync Gradle (File > Sync Project with Gradle Files)

Rebuild Project (Build > Rebuild)

Run the app again.

Tip If you see:

android.arch.persistence.room:migration But not:

android.arch.persistence.room:runtime Then you're only seeing Room's migration support — not the full library.

VaradGupta23 avatar Aug 04 '25 05:08 VaradGupta23