gpt4 book ai didi

android - 错误 : [MissingType]: Element 'xxxxx.AppDatabase.room' references a type that is not present

转载 作者:行者123 更新时间:2023-12-04 23:39:57 36 4
gpt4 key购买 nike

错误:[MissingType]:元素 'xxxxx.AppDatabase.room' 引用了不存在的类型
当我尝试编译我的代码时,我得到了标题中提到的错误。看来我的 Room 有问题,导致了这种情况。 Kotlin kapt 给出了这个错误。我该如何解决?
项目级 Gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {


ext.kotlin_version = '1.5.31'
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }

}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"
classpath 'com.google.gms:google-services:4.3.10'

def nav_version = "2.3.5"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}

}

allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url 'https://jitpack.io' }
maven { url "https://maven.google.com" } // Google's Maven repository
maven { url 'https://developer.huawei.com/repo/' } // HUAWEI Maven repository

}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
应用级 Gradle
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
}

android {
compileSdkVersion 31
buildToolsVersion "30.0.0"
flavorDimensions "default"
viewBinding {
enabled = true
}

defaultConfig {
applicationId "com.ege.altaga"
minSdkVersion 21
targetSdkVersion 31
versionCode 1
versionName "1.0"
multiDexEnabled true


testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

signingConfigs {
release {
storeFile file("key.keystore.jks")
storePassword 'android'
keyAlias 'altaga'
keyPassword 'android'
}

}

buildTypes {
debug {
minifyEnabled false
shrinkResources false
debuggable true
aaptOptions.cruncherEnabled = false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'


// resValue("string", "google_device_verification_api_key", "AIzaSyDNLDM08-vLp9uszlNJH1SJW1y7oUqsA-U")
}

release {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
minifyEnabled true
shrinkResources false
debuggable false
signingConfig signingConfigs.release
zipAlignEnabled true
// resValue("string", "google_device_verification_api_key", "AIzaSyDNLDM08-vLp9uszlNJH1SJW1y7oUqsA-U")
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
// coreLibraryDesugaringEnabled true
}
configurations {
cleanedAnnotations
compile.exclude group: 'org.jetbrains', module: 'annotations'
}
kotlinOptions {
jvmTarget = '1.8'
}

}

dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib:1.4.32"
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
implementation 'com.github.bumptech.glide:glide:4.12.0'
implementation 'com.google.code.gson:gson:2.8.7'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'io.reactivex:rxjava:1.1.6'
implementation 'io.reactivex:rxandroid:1.2.1'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'

kapt 'com.github.bumptech.glide:compiler:4.12.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0'
def room_version = "2.4.0-beta02"

implementation "androidx.room:room-ktx:$room_version"
kapt "androidx.room:room-compiler:$room_version"
// annotationProcessor "androidx.room:room-compiler:$room_version"

// optional - RxJava2 support for Room
implementation "androidx.room:room-rxjava2:$room_version"
}
应用数据库类
package com.ege.altaga.data

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.ege.altaga.data.database.player.PlayerDAO
import com.ege.altaga.data.database.player.PlayerEntity
import com.ege.altaga.data.database.square.SquareDAO
import com.ege.altaga.data.database.square.SquareEntity

@Database(entities = [(PlayerEntity::class),(SquareEntity::class)],version = 1)
abstract class AltagaDB : RoomDatabase() {

abstract fun playerDAO() : PlayerDAO<PlayerEntity>
abstract fun squareDAO() : SquareDAO<SquareEntity>

companion object {
@Volatile var instance: AltagaDB? = null

fun getDatabase(context: Context): AltagaDB =
instance ?: synchronized(this) { instance ?: buildDatabase(context.applicationContext).also { instance = it } }

private fun buildDatabase(appContext: Context) =
Room.databaseBuilder(appContext, AltagaDB::class.java, "AltagaDB")
.fallbackToDestructiveMigration()
.build()
}
}

最佳答案

我在使用带有 kotlin v1.5.31 的房间 v2.4.1 时遇到了同样的问题。解决方案是将 kotlin 版本更改为 1.6.0。

关于android - 错误 : [MissingType]: Element 'xxxxx.AppDatabase.room' references a type that is not present,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70216485/

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