1、首先就是要确保GreenDao的版本;
classpath 'org.greenrobot:greendao-gradle-plugin:3.3.1'
项目中依赖3.3.0就行了(虽然GTP认为要使用3.3.1,但至少我目前编译是无法通过的)
implementation 'org.greenrobot:greendao:3.3.0'
2、其次还有一个问题
':app:compileDebugKotlin' uses this output of task ':app:greendao' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
这个问题是和Kotlin-TASK编译有关的。
GPT推荐的解决方案是
afterEvaluate {
tasks.named('compileDebugKotlin') {
dependsOn(tasks.named('greendao'))
}
// 如果还有其他变体
tasks.named('compileReleaseKotlin') {
dependsOn(tasks.named('greendao'))
}
}
问题原因
在 AGP 8.0 + GreenDAO 3.3.1 组合中,Gradle 需要明确知道:
greendao 任务必须在 compileDebugKotlin 之前执行
Kotlin 编译依赖于 GreenDAO 生成的代码