执行org.jetbrains.kotlin.gradle.internal.KaptExecution> java.lang.reflect.InvocationTargetException时发生故障(无错误消息)

亚历克斯

Android Studio给出了错误:

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 Coroutines并将其与Room数据库一起使用。但是在添加所有库之后,我得到了这个错误。这些都是来自编译器的信息。

我已经确定,这是因为注释@Database。如果我删除了此注释,则不会出现该错误,但Room也不起作用。

我的gradle文件:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
//apply plugin: 'androidx.navigation.safeargs'

kotlin {
    experimental {
        coroutines 'enable'
    }
}

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "com.bestcred.coursetthree"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        //vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    // Enables data binding.
    buildFeatures {
        dataBinding true
    }
}

dependencies {


    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    // Support libraries
    implementation "androidx.appcompat:appcompat:1.2.0"
    implementation 'com.google.android.material:material:1.2.0'
    implementation "androidx.fragment:fragment:1.2.5"
    implementation "androidx.constraintlayout:constraintlayout:2.0.0"

    // Android KTX
    implementation 'androidx.core:core-ktx:1.3.1'

    // Room and Lifecycle dependencies
    implementation "androidx.room:room-runtime:$room_version"
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    kapt "android.arch.persistence.room:compiler:$room_version"

    // Kotlin Extensions and Coroutines support for Room
    implementation "androidx.room:room-ktx:$room_version"

    // Coroutines
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutine_version"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutine_version"

}

kotlin_version = "1.4.0"
room_version = "2.2.5"
coroutine_version = '1.3.9'

我更新了Room版本并添加了Kotlin Coroutines。什么问题?在此处输入图片说明

亚历克斯

您需要更改:

kapt "android.arch.persistence.room:compiler:$room_version"

kapt "androidx.room:room-compiler:$room_version"

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章