Android studio 接收到“任务执行失败”:应用程序:kaptDebugKotlin“。错误

Android studio 接收到“任务执行失败”:应用程序:kaptDebugKotlin“。错误,android-studio,kotlin,Android Studio,Kotlin,我正在尝试运行一个应用程序,我正在编写Android Studio 4.1开发概要,第76章。它是一个使用Android Room持久性库的应用程序 我得到的错误是: Execution failed for task ':app:kaptDebugKotlin'. > A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution > java.lang.reflect

我正在尝试运行一个应用程序,我正在编写Android Studio 4.1开发概要,第76章。它是一个使用Android Room持久性库的应用程序

我得到的错误是:

Execution failed for task ':app:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
   > java.lang.reflect.InvocationTargetException (no error message)
虽然对Kotlin和Android Studio来说还很陌生,但我相信这个错误与我的build.gradle应用程序文件的设置有关,如下所示

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
    id 'kotlin-kapt'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    defaultConfig {
        applicationId "us.jordanakellogg.roomdemo"
        minSdkVersion 26
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildFeatures {
        viewBinding true
    }

    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'
    }
 
}

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
    implementation 'androidx.room:room-runtime:2.2.5'
    implementation 'androidx.fragment:fragment-ktx:1.2.5'
    kapt "androidx.room:room-compiler:2.2.5"
    kapt 'androidx.databinding:databinding-compiler-common:4.0.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

}  
我会提供我的DAO类,我觉得可能也有问题

import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query


@Dao
interface ProductDAO {

    @Insert
    fun insertProduct(product: Product)

    @Query("SELECT * FROM products WHERE productName=:name")
    fun findProduct(name: String): List<Product>

    @Query("DELETE FROM products WHERE productName=:name")
    fun deleteProduct(name: String)

    @Query("SELECT * FROM products")
    fun getAllProducts(): LiveData<List<Product>>
}

您能帮我指出正确的方向吗?这样我就可以成功地测试此应用程序,而不会收到任务“:app:kaptDebugKotlin”的执行失败消息。错误?

您解决了吗?在我的例子中,我为表列添加了一个不可为null的变量。我把它设为可空变量,错误就消失了。我仍然认为,这可能也是过时依赖项的问题。您解决了吗?在我的例子中,我为表列添加了一个不可为null的变量。我把它设为可空变量,错误就消失了。我仍然认为,这可能也是过时的依赖关系的问题。