运行应用程序时出现以下错误
java.lang.RuntimeException: cannot find implementation for com.abc.db.abdDB. abcDB_Impl does not exist
我的build.gradle有以下配置:
implementation "androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:2.0.0-alpha1"
implementation "androidx.room:room-runtime:2.0.0-alpha1"
annotationProcessor "androidx.room:room-compiler:2.0.0-alpha1"
我的数据库课程:
fun getDatabase(context: Context): abcDB? {
if (dbInstance == null) {
synchronized(abcDB::class.java) {
if (dbInstance == null) {
dbInstance = Room.databaseBuilder(context.applicationContext,
abcDB::class.java, "abc_db")
.fallbackToDestructiveMigration()
.addCallback(sRoomDatabaseCallback)
.build()
}
}
}
return dbInstance
}
有没有人尝试使用androidX API?有人可以帮忙找到解决方案吗?
答案 0 :(得分:24)
如果您使用Kotlin,则必须使用kapt
代替annotationProcessor
,并且还必须应用kotlin-kapt
插件。
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
dependencies {
implementation "androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1"
kapt "androidx.lifecycle:lifecycle-compiler:2.0.0-alpha1"
implementation "androidx.room:room-runtime:2.0.0-alpha1"
kapt "androidx.room:room-compiler:2.0.0-alpha1"
答案 1 :(得分:0)
对于 Java
在应用 build.gradle 中
使用
implementation 'android.arch.persistence.room:runtime:1.1.1'
annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'