gpt4 book ai didi

android - 房间持久性库 : Cannot resolve symbol Room

转载 作者:太空宇宙 更新时间:2023-11-03 12:14:28 25 4
gpt4 key购买 nike

我使用具有以下 gradle 设置的 Android Studio 3.0 Beta 2

我可以搜索 RxRoom 但没有创建 Room 类。按照说明 Add Components 后,我不能在我的 Fragment 中使用 Room 类。

这个类在单独的模块中,应用程序模块不包含任何房间库依赖项。

错误在 IDE 中显示为“无法解析符号房间”。

enter image description here

构建.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,现在房间类又回来了。我不知道为什么这个类在 alpha9 中消失了,但至少它是解决方法。

最佳答案

经过一周的试用,我发现即使出现编译时错误,我也可以运行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
}
}

关于android - 房间持久性库 : Cannot resolve symbol Room,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46050113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com