使用Room时添加kapt导致编译错误

9

我添加了apply plugin: 'kotlin-kapt',以便能够使用Rooms注释处理器:

compile "android.arch.persistence.room:runtime:1.0.0"
kapt "android.arch.persistence.room:compiler:1.0.0"

然而,在构建我的项目时,我遇到了以下问题:
Folder C:\Users\...\app\build\generated\source\kaptKotlin\debug


Folder C:\Users\...\app\build\generated\source\kaptKotlin\release


3rd-party Gradle plug-ins may be the cause

如果我取消使用kapt只使用annotationProcessor,那么应用程序会崩溃并显示以下错误信息:

java.lang.RuntimeException: cannot find implementation for com.example..data.database.Appdatabase. Appdatabase_Impl does not exist

你有什么想法如何使用Room吗?

@EpicPandaForce 不,我有常见的Android支持库,但我只有Room注释库。 - Derek
有数据绑定的机会吗? - EpicPandaForce
如果您正在使用Kotlin版本1.2.31,可能会遇到此类错误。现在请使用Kotlin版本1.2.30。 - Nabin Khatiwada
1
你解决了这个错误吗?我也遇到了同样的问题。 - felipe.rce
仍然发生在Kotlin 1.2.51和Android Studio 3.1.4中。 - Wood
显示剩余4条评论
2个回答

1
我遇到了类似的问题。
请前往:
运行 -> 编辑配置 -> 通用
在底部,有一个名为
在启动之前:Gradle-Aware、Active 工具窗口
删除
即时应用程序提供
并保留 Gradle-aware Make。

0

我删除了两个文件夹 app\build\generated\source\kaptKotlin\debug 和 app\build\generated\source\kaptKotlin\release("debug" 和 "release"),并在 gradle 中添加了以下内容:

kapt {
        mapDiagnosticLocations = true
    }

那么项目就可以顺利同步了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接