我使用Android Studio 3.0 Beta 2并使用以下gradle设置
我可以搜索RxRoom,但没有成立Room类。按照Add Components指令后,我不能在片段中使用Room类。
此类位于单独的模块中,app模块不包含任何房间库依赖项。
错误显示"无法解析符号室"在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"
}
更新 我试图将房间库降级为alpha8,而Room类现在又回来了。我不知道为什么这个类在alpha9中消失了,但至少它是解决方法。
答案 0 :(得分:4)
经过一周的试用,我发现我可以运行apk,即使我有编译时错误。我尝试通过以下方式解决问题以解决编译错误。
更改
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha9"
要
implementation "android.arch.persistence.room:compiler:1.0.0-alpha9"
并添加以下Disable the error check from Migrate to Android Plugin for Gradle 3.0
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath = true
}
}
答案 1 :(得分:1)
请将所有Room
依赖项从implementation
更改为build.gradle中的api
答案 2 :(得分:1)
如果在“房间实体”类上收到错误“无法解析符号” ,请尝试使用此技巧:在类中添加一个虚拟属性。然后清理并重建您的项目。这应该刷新实体。然后取出假人。
示例:
@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