【发布时间】:2022-08-14 13:02:55
【问题描述】:
我正在尝试将 build.gradle 配置为使用 Room
错误仍然存在:
Unresolved reference: room
因此,注释仍然未解决
@Entity
经过7个教程和3天,我不得不投降并寻求帮助。
在这里我粘贴我的 build.grade。我从这个谷歌教程中得到了它:
https://developer.android.com/codelabs/android-room-with-a-view-kotlin#3
顺便说一句,这与其他谷歌教程完全不同:
https://developer.android.com/training/data-storage/room
我究竟做错了什么?
plugins {
id \'com.android.application\'
id \'org.jetbrains.kotlin.android\'
id \'kotlin-kapt\'
}
android {
compileSdk 32
defaultConfig {
applicationId \"com.firewalker.mouth_conjugation\"
minSdk 21
targetSdk 32
versionCode 1
versionName \"1.0\"
testInstrumentationRunner \"androidx.test.runner.AndroidJUnitRunner\"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile(\'proguard-android-optimize.txt\'), \'proguard-rules.pro\'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = \'1.8\'
}
packagingOptions {
exclude \'META-INF/atomicfu.kotlin_module\'
}
}
dependencies {
implementation \"androidx.appcompat:appcompat:$rootProject.appCompatVersion\"
implementation \"androidx.activity:activity-ktx:$rootProject.activityVersion\"
// Dependencies for working with Architecture components
// You\'ll probably have to update the version numbers in build.gradle (Project)
// Room components
implementation \"androidx.room:room-ktx:$rootProject.roomVersion\"
kapt \"androidx.room:room-compiler:$rootProject.roomVersion\"
androidTestImplementation \"androidx.room:room-testing:$rootProject.roomVersion\"
// Lifecycle components
implementation \"androidx.lifecycle:lifecycle-viewmodel-ktx:$rootProject.lifecycleVersion\"
implementation \"androidx.lifecycle:lifecycle-livedata-ktx:$rootProject.lifecycleVersion\"
implementation \"androidx.lifecycle:lifecycle-common-java8:$rootProject.lifecycleVersion\"
// Kotlin components
implementation \"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version\"
api \"org.jetbrains.kotlinx:kotlinx-coroutines-core:$rootProject.coroutines\"
api \"org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.coroutines\"
// UI
implementation \"androidx.constraintlayout:constraintlayout:$rootProject.constraintLayoutVersion\"
implementation \"com.google.android.material:material:$rootProject.materialVersion\"
// Testing
testImplementation \"junit:junit:$rootProject.junitVersion\"
androidTestImplementation \"androidx.arch.core:core-testing:$rootProject.coreTestingVersion\"
androidTestImplementation (\"androidx.test.espresso:espresso-core:$rootProject.espressoVersion\", {
exclude group: \'com.android.support\', module: \'support-annotations\'
})
androidTestImplementation \"androidx.test.ext:junit:$rootProject.androidxJunitVersion\"
}```
-
你注意评论了吗// You\'ll probably have to update the version numbers in build.gradle (Project)并设置
roomVersion因此?如果不是$rootProject.roomVersion,您可以在上面编写实际版本,例如2.4.2,因此您可以使用implementation \"androidx.room:room-ktx:2.4.2\"而不是implementation \"androidx.room:room-ktx:$rootProject.roomVersion\"。第二个链接包括在 build.gradle 中设置 roomVersion 值
标签: android-studio kotlin android-room