更新:尝试麦克的建议,仍然得到错误:
ext {
kotlin_version = '1.1.50'
arch_lib_version = '1.0.0-alpha9'
gradle_version = '2.3.3'
}
kapt {
generateStubs = true
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile "android.arch.lifecycle:runtime:$arch_lib_version"
compile "android.arch.lifecycle:extensions:$arch_lib_version"
compile "android.arch.persistence.room:runtime:$arch_lib_version"
//annotationProcessor "android.arch.persistence.room:compiler:$arch_lib_version"
kapt "android.arch.persistence.room:compiler:$arch_lib_version"
annotationProcessor "android.arch.lifecycle:compiler:$arch_lib_version"
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
Error:Annotation processor '__gen.AnnotationProcessorWrapper_robotiumDebug_android_arch_persistence_room_RoomProcessor' not found
============
在gradle这个:
ext {
arch_lib_version = '1.0.0-alpha9'
}
compile "android.arch.persistence.room:runtime:$arch_lib_version"
annotationProcessor "android.arch.persistence.room:compiler:$arch_lib_version"
//kapt "android.arch.persistence.room:compiler:$arch_lib_version"
使用kapt,它会给编译错误的尝试:
Error:Annotation processor '__gen.AnnotationProcessorWrapper_robotiumDebug_android_arch_persistence_room_RoomProcessor' not found
代码段低于:
@Database(entities = arrayOf(CModel::class), version = 1)
abstract class CDatabase : RoomDatabase() {
abstract fun cModel(): DbCDao
companion object {
fun getDatabase(context: Context): CDatabase {
return Room.databaseBuilder(context.applicationContext, CDatabase::class.java, “database”)
.build() //<=== throw here saying CDatabase_Impl does not exist
}
}
}
表CLAS:
@Entity(tableName = “table”)
class CModel() : ICDelegate {
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = “index")
private var mIndex: Long = -1
@ColumnInfo(name = "parentIndex")
private var mParentIndex: Long = -1
……
}
在DAO接口认定中:
@Dao
interface DbCDao {
@Query("select * from table")
fun loadAllAccountss(): List<CModel>
@Query("select * from table where index = :index")
fun loadCsByIndex(index: Int): CModel
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertC(ac: CModel) : Long
@Update(onConflict = OnConflictStrategy.REPLACE)
fun updateAC(ac: CModel) : Int
@Delete
fun deleteAc(ac: CModel) : Int
@Query("DELETE FROM table”)
fun deleteAllCs()
}
例外:
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by:
java.lang.RuntimeException: cannot find implementation for com.myproject.data. CDatabase. CDatabase_Impl does not exist
at
android.arch.persistence.room.Room.getGeneratedImplementation(Room.java:90)
at
android.arch.persistence.room.RoomDatabase $ Builder.build(RoomDatabase.java:440)
试过有人建议并不起作用:
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation":
"$projectDir/schemas".toString()]
}
}