Room Persistence Library : Cannot resolve symbol Room
Solution 1
After a week trial ,I find that I can run the apk even I have the compile time error. I tried to resolve the issue by the following way to resolve the compile error.
Change
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha9"
To
implementation "android.arch.persistence.room:compiler:1.0.0-alpha9"
And add the following Disable the error check from Migrate to Android Plugin for Gradle 3.0
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath = true
}
}
Solution 2
Please change all the Room
dependency from implementation
into api
in the build.gradle
Solution 3
If you are getting the error "Cannot resolve symbol" on your Room Entity classes, try this hack: add a dummy property to your class. Then clean and rebuild your project. This should refresh the entities. Then remove the dummy.
Example:
@Query("select * from my_entity where name = :name") --> Cannot resolve symbol name...
MyEntity getMyEntityByName(String name);
@Entity(indices = {@Index(value = {"name"})}, tableName = "my_entity")
public class MyEntity {
other properties ....
public int dummy; --> add and remove this
Long Ranger
Learn code every day and save time for my life. My First Kotlin project https://github.com/charlesng/Vegas Currently I am trying to make a sample application with the new android app architecture. Feel free to make any comment on it. https://github.com/charlesng/SampleAppArch
Updated on June 05, 2022Comments
-
Long Ranger about 2 years
I used Android Studio 3.0 Beta 2 with the following gradle settings
I can search the RxRoom but no Room class founded. After following the instruction Add Components , I cannot use Room class in my Fragment.
This class is in the seperate module, the app module does not contains any room library dependency.
The error showed "Cannot resolve symbol Room" in IDE.
build.gradle
apply plugin: 'com.android.library' android { compileSdkVersion 26 buildToolsVersion "26.0.1" defaultConfig { minSdkVersion 15 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" javaCompileOptions { annotationProcessorOptions { arguments = ["room.schemaLocation": "$projectDir/schemas".toString()] } } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } compileOptions { targetCompatibility 1.8 sourceCompatibility 1.8 } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:26.0.2' implementation 'com.android.support.constraint:constraint-layout:1.0.2' implementation 'com.android.support:design:26.0.2' implementation 'com.android.support:support-v4:26.0.2' implementation 'com.android.support:recyclerview-v7:26.0.2' testImplementation 'junit:junit:4.12' androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', { exclude group: 'com.android.support', module: 'support-annotations' }) implementation "android.arch.persistence.room:runtime:1.0.0-alpha9" annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha9" testImplementation "android.arch.persistence.room:testing:1.0.0-alpha9" implementation "android.arch.persistence.room:rxjava2:1.0.0-alpha9" }
Updated I have tried to downgrade the room library to alpha8 first and the Room class come back now. I have no idea why this class disappeared in the alpha9 but at least it is the workaround.