8
votes

I am using Android Room Persistence library (v.1.0.0-alpha1) in my app. Although it is working fine, when I open model class (Kotlin Data class) in Android studio, it shows Unresolved reference for all annotations used for Room database like @Entity, @ColumnInfo etc. I tried changing version of arch library to 1.0.0-alpha5 but result was same.

In Lint inspection it is showing Remove deprecated symbol import for all imported annotations.AS was not showing this error previously.

How can I resolve this issue

Edit Following are imports I have added in my build.gradle

compile "android.arch.persistence.room:runtime:1.0.0-alpha5"

compile "android.arch.persistence.room:rxjava2:1.0.0-alpha5"

annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha5"

kapt "android.arch.persistence.room:compiler:1.0.0-alpha5"
3
Can you paste all the Persistence Library related imports from your build.gradle? Did you add the import for annotation processor? - lidkxx
Have you tried clean/rebuild? Do you have Maven added in build.gradle?Documentation: developer.android.com/topic/libraries/architecture/… Also, in this project you can check the correct setup for Room github.com/riggaroo/android-arch-components-date-countdown/blob/… Check out this question also: stackoverflow.com/questions/44142964/… - lidkxx
Could you pour in some additional code ? Like an entity and related DAO and DB. - Oyzuu
@lidkxx I am not sure whether this is correct implementation or not but after i put compile "android.arch.persistence.room:common:1.0.0-alpha5" in build.gradle above problem got solved - silwar

3 Answers

6
votes

Here you have an example.

https://github.com/jsperk/PocRoom

Remember, you need add:

Gradle (Project)--> maven

Gradle (Module App) dependencies -->

implementation "android.arch.persistence.room:runtime:1.0.0"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0"
testImplementation "android.arch.persistence.room:testing:1.0.0"
implementation "android.arch.persistence.room:rxjava2:1.0.0"
3
votes

In my project, I have this question cause I'm using

android.arch.lifecycle:livedata:1.1.1

than no matter using room with version 1.1.1 or 1.0.0, it still can't find the android.arch.persistence.room.Entity.

I've searched for a long time, till I found that, when I delete the LiveData implementation, the problem solved. Then I notice that, the version of these two libraries conflict. At last, I use the same version of 1.1.0 for livedata and room (since livedata have no version of 1.0.0), and solved it.

def arch_version = "1.1.0"
implementation  "android.arch.persistence.room:runtime:$arch_version"
annotationProcessor "android.arch.persistence.room:compiler:$arch_version"
implementation "android.arch.persistence.room:rxjava2:$arch_version"
implementation "android.arch.persistence.room:common:$arch_version"
implementation "android.arch.lifecycle:livedata:$arch_version"
implementation "android.arch.lifecycle:extensions:$arch_version"
0
votes

Adding these dependencies to your Gradle(Module App) file will solve it:-

implementation "android.arch.persistence.room:runtime:1.1.1"
annotationProcessor "android.arch.persistence.room:compiler:1.1.1"
testImplementation "android.arch.persistence.room:testing:1.1.1"
implementation "android.arch.persistence.room:rxjava2:1.1.1"