发现一个很酷的东西,在KSP中无法调用Java的类
sky130 opened this issue · comments
当我添加注解时,编译报错
@BindingClass<ItemMiMiwuDeviceBinding> // this
@Keep
@Entity(tableName = "miwu_device")
data class MiwuDevice()
> Task :app:kspDebugKotlin FAILED
e: [ksp] C:/Users/z1303/AndroidStudioProjects/MiHome/app/src/main/java/com/github/miwu/logic/database/model/MiwuDevice.kt:17: [MissingType]: Element 'com.github.miwu.logic.database.model.MiwuDevice' references a type that is not present
e: [ksp] androidx.room.RoomKspProcessor was unable to process 'com.github.miwu.logic.database.AppDatabase' because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code.
e: Error occurred in KSP, check log for detail
[ksp] C:/Users/z1303/AndroidStudioProjects/MiHome/app/src/main/java/com/github/miwu/logic/database/model/MiwuDevice.kt:17: [MissingType]: Element 'com.github.miwu.logic.database.model.MiwuDevice' references a type that is not present
原因是databinding的类是java的
解决方案
android{
...
sourceSets {
this["release"].java.srcDir("build/generated/data_binding_base_class_source_out/release/out")
this["debug"].java.srcDir("build/generated/data_binding_base_class_source_out/debug/out")
}
}
dependencies{
...
}
afterEvaluate {
tasks.named("kspDebugKotlin") {
dependsOn("dataBindingGenBaseClassesDebug")
}
}