【问题标题】:Android Kotlin: Error when using 'suspend' in DAO - Following CodeLabs guideAndroid Kotlin:在 DAO 中使用“暂停”时出错 - 遵循 CodeLabs 指南
【发布时间】:2020-08-06 02:37:42
【问题描述】:

我一直在关注 CodeLabs 的本指南,并在 this section 上显示在 DAO 方法中使用了 'suspend' 关键字,但是当我这样做时,我得到了这个错误:

error: To use Coroutine features, you must add `ktx` artifact from Room as a dependency. androidx.room:room-ktx:<version>
    public abstract java.lang.Object deleteAll(@org.jetbrains.annotations.NotNull()
    public abstract java.lang.Object insert(@org.jetbrains.annotations.NotNull()
                                     ^

我在网上查了一下,但人们说你不能在 DAO 方法中使用协程。

我还添加了此步骤之前的所有 build.gradle 导入 here

【问题讨论】:

    标签: android kotlin gradle coroutine kotlin-coroutines


    【解决方案1】:

    好的,我发现了问题所在。即使我将协程文件添加到 build.grade 文件中,我也需要添加 Room 的特定协程文件,即:

    implementation "androidx.room:room-ktx:2.2.5"
    

    这将是使用带有 DAO 方法的协程。

    我很困惑,因为我以为我在上一步中添加了所有必要的文件。

    【讨论】:

    • 就我而言,我需要更新这个库的版本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-15
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-25
    相关资源
    最近更新 更多