1、首先就是要確保GreenDao的版本;
classpath 'org.greenrobot:greendao-gradle-plugin:3.3.1'
項(xiàng)目中依賴3.3.0就行了(雖然GTP認(rèn)為要使用3.3.1,但至少我目前編譯是無法通過的)
implementation 'org.greenrobot:greendao:3.3.0'
2、其次還有一個(gè)問題
':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.
這個(gè)問題是和Kotlin-TASK編譯有關(guān)的。
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 任務(wù)必須在 compileDebugKotlin 之前執(zhí)行
Kotlin 編譯依賴于 GreenDAO 生成的代碼