gpt4 book ai didi

kotlin - 执行org.jetbrains.kotlin.gradle.internal.KaptExecution Room数据库时发生故障

转载 作者:行者123 更新时间:2023-12-02 13:41:20 25 4
gpt4 key购买 nike

我已经为这个错误苦苦挣扎了许多小时,并且能够追溯到第一次发生该错误时。将@Database批注添加到数据库类后,我立即收到一条错误消息,提示“执行org.jetbrains.kotlin.gradle.internal.KaptExecution时发生故障”,有人可以提出建议吗?为了完成这一点,我不得不退后几个小时的工作,这让我很伤脑筋。
GameDatabase.kt

package com.arcsoft.psncollection.data

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase

@Database(entities = [Game::class], version = 1, exportSchema = true)
abstract class GameDatabase: RoomDatabase() {
abstract fun monsterDao(): GameDao

companion object {
@Volatile
private var INSTANCE: GameDatabase? = null

fun getDatabase(context: Context): GameDatabase {
if (INSTANCE == null) {
synchronized(this) {
INSTANCE = Room.databaseBuilder(
context.applicationContext,
GameDatabase::class.java,
"games.db"
).build()
}
}
return INSTANCE!!
}
}
}
Game.kt
package com.arcsoft.psncollection.data

import androidx.room.Entity
import androidx.room.PrimaryKey
import com.arcsoft.psncollection.IMAGE_BASE_URL

@Entity(tableName = "games")
data class Game (
@PrimaryKey(autoGenerate = true)
val id: Int,
val cover: Cover,
val name: String,
val popularity: Double,
val imageFile: String,
var summary: String,
var time_to_beat: String,
var aggregated_rating: Double
)
{
val imageUrl
get() = "$IMAGE_BASE_URL/$imageFile.webp"
val thumbnailUrl
get() = "$IMAGE_BASE_URL/${imageFile}_tn.webp"
}
GameDao.kt
package com.arcsoft.psncollection.data

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query

@Dao
interface GameDao {
@Query("SELECT * from games")
fun getAll(): List<Game>

@Insert
suspend fun insertMonster(monster: Game)

@Insert
suspend fun insertMonsters(monsters: List<Game>)

@Query("DELETE from games")
suspend fun deleteAll()

}
build.gradle
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 30
buildToolsVersion "30.0.0"
defaultConfig {
applicationId "com.arcsoft.psncollection"
minSdkVersion 24
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
dataBinding{
enabled = true
}
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.0'
implementation 'com.github.husnjak:IGDB-API-JVM:0.7'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.squareup.picasso:picasso:2.71828'

implementation"com.squareup.moshi:moshi-kotlin:1.8.0"

def retrofit2_version = "2.6.0"
implementation "com.squareup.retrofit2:retrofit:$retrofit2_version"
implementation "com.squareup.retrofit2:converter-moshi:$retrofit2_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit2_version"

def coroutines_version = "1.2.1"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"

def glide_version = "4.9.0"
implementation "com.github.bumptech.glide:glide:$glide_version"
annotationProcessor "com.github.bumptech.glide:compiler:$glide_version"

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

}

最佳答案

您是否尝试过在Debug模式下进行编译以获取更多信息?您可以通过以下方法来执行此操作:单击Android Studio右侧栏中的 Gradle ,然后单击 Tasks / other / compileDebugKotlin 。清理和重建项目大部分时间对我有帮助。
您的数据库类似乎还不错。。。将Room与Kotlin协程一起使用,对吗?所有@Query批注都在编译时进行了验证,因此可能是问题所在。我建议在您的Dao文件内的suspend中添加fun getAll()关键字,以便Room可以保证它将在后台线程上运行。
另外,我最近在Room中使用了协程,如果您想查看我的代码(在Github上),可以使用link,这不是最好的示例,但是它可以以某种方式为您提供帮助。

关于kotlin - 执行org.jetbrains.kotlin.gradle.internal.KaptExecution Room数据库时发生故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63195618/

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