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'

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>

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

正如我已经说过的,我的档案现在非常混乱,我将感谢any人的帮助,让它变得更明智.谢谢,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'
}

推荐答案

You're using

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

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"

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.

Kotlin相关问答推荐

直接从SON解析NonEmptyList

来自SnapshotFlow的单元测试StateFlow仅发出initialValue

Kotlin—从列表中枚举属性计算不同值的数量

如何在Kotlin中为两个数据类创建可重用的方法?

在Kotlin Jetpack中重用下拉菜单

映射中列表类型的Kotlin可空接收器?

如何使用multiset与JOOQ获取关联的记录列表?

在Kotlin lambda的参数中如何指定函数类型?

为什么 trySend 会发出假数据?

Jetpack Compose 中的连续重组

在 kotlin 中重载函数时,我在一些非常基本的代码上不断收到类型不匹配

嵌套数组 indexOf()

kotlin 扩展属性的惰性初始化器中的这个引用

无法在 kotlin android 中以编程方式禁用 EditText

如何在 kotlin 中生成 json 对象?

如何将vararg转换为list?

未找到导入 kotlinx.coroutines.flow.*

Android插件2.2.0-alpha1无法使用Kotlin编译

参数不匹配;SimpleXML

如何启用spring security kotlin DSL?