为什么要导入androidx.room.Entity;无法识别,如何使用roomdb注解?

问题描述 投票:0回答:2

为什么 Android studio 中的类文件无法识别

import androidx.room.Entity;
? 这些 @Entity、@ColunInfo 等都不是。我正在使用 Android studio 和 Java

我在依赖项中添加了以下内容

plugins {
    id 'com.android.application'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.example.paragroom"
        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
    }
}

dependencies {
    def room_version = "2.4.3"
    implementation "androidx.room:room-runtime:$room_version"
    annotationProcessor "androidx.room:room-compiler:$room_version"
    implementation 'androidx.appcompat:appcompat:1.5.1'
    implementation 'com.google.android.material:material:1.6.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
    
android android-studio annotations
2个回答
1
投票

我不确定你的问题。这是我的 gradle 中有关 room 的所有内容(我正在使用 kotlin)

    //room
    def room_version = "2.4.2"
    implementation "androidx.room:room-runtime:$room_version"
    implementation "androidx.room:room-ktx:$room_version"
    kapt  "androidx.room:room-compiler:$room_version"

您是否尝试过使缓存无效并重新启动 IDE?


0
投票

在 gradle 中,应取消选中“切换离线模式”

© www.soinside.com 2019 - 2024. All rights reserved.