Android - AGP 8.0 之后与Greendao的兼容问题解决方案

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 生成的代码

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容