重复构建失败“要使用协同程序功能,必须添加`ktx`........" [英] Repeated Build fails "To use Coroutine features, you must add `ktx`......."

查看:165
本文介绍了重复构建失败“要使用协同程序功能,必须添加`ktx`........"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Kotlin和Android Studio的新手,我当前的问题是...
我正在尝试使Codelabs的"android-room-with-a-view-kotlin"正常工作,并且在解决各种构建错误的同时,我认为我的build.gradle变得非常混乱!我通过添加依赖项

I'm new to Kotlin and Android Studio and my current problem is this...
I'm trying get the Codelabs "android-room-with-a-view-kotlin" to work and whilst fixing various build errors along the way, I think my build.gradle has become very confused! I corrected the last build failure at Word.kt by adding the dependency

kapt 'androidx.room:room-ktx:2.2.1'

下一个版本进一步扩展到 WordDao.kt ,但由于相同类型的错误而失败.

The next build went a little further on to WordDao.kt but failed with the same type of error..

WordDao.java:21: error: To use Coroutine features, you must add `ktx` artifact from Room as a dependency. androidx.room:room-ktx:<version>

我无法继续,因为我不知道要在build.gradle中进行什么更改,因为我已经添加了该依赖项?

I'm unable to continue because I don't know what to change in the build.gradle as I've already added that dependency?

就像我说过的那样,我的文件现在非常混乱,我希望得到 任何 帮助,使文件更加明智.谢谢,DaveInUk

As I've said my file is now very confused and I would appreciate any assistance in making it more sensible. Thanks, DaveInUk

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: "kotlin-kapt"

android {
    compileSdkVersion 28
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.prepopplus"
        //was minSdkVersion 15  Note Old phone is API16
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }

        packagingOptions {
            exclude "META-INF/atomicfu.kotlin_module"
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.50"

    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    kapt 'androidx.room:room-ktx:2.2.1'
    kapt "androidx.room:room-compiler:2.2.1"
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0-rc01'

    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    kapt "android.arch.persistence.room:compiler:1.1.1"
    kapt "android.arch.lifecycle:compiler:1.1.1"

    implementation 'androidx.room:room-runtime:2.2.1'
}

推荐答案

您正在使用

kapt 'androidx.room:room-ktx:2.2.1'
kapt "androidx.room:room-compiler:2.2.1"

但是 androidx.room:room-ktx 不是 kapt 的输入,而是正常的 implementation 依赖项( room-compiler 是注释处理器).因此,您的依赖关系必须是

But androidx.room:room-ktx is not an input into kapt, but a normal implementation dependency (the room-compiler is the annotation processor). Therefore your dependencies need to be

implementation 'androidx.room:room-ktx:2.2.1'
kapt "androidx.room:room-compiler:2.2.1"

根据声明会议室相关性文档.请注意, room-ktx 会将 room-runtime 作为传递依赖项引入,因此,如果存在这种依赖关系,则可以删除该依赖项并仅依赖 room-ktx 你想要的.

As per the Declaring Room dependencies documentation. Note that room-ktx pulls in room-runtime as a transitive dependency, so you can remove that dependency and rely solely on room-ktx if you want.

这篇关于重复构建失败“要使用协同程序功能,必须添加`ktx`........"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆