更新了gradle到3.5.3导致GreenDao初始化失败

今天更新了下项目的gradle最新版本,结果运行导致GreenDao报错Could not init DAOConfig
最后通过在GreenDao的github的Issues中找到了原因解决方法

Hello,

We also faced this issue after update to AGP 3.5.0.
This is related to proguard/D8 rules.

I noticed that its because of -keep class **$Properties line (which was before in GreenDao documentation). To AGP version 3.4.2 this line keeps all generated **$Properties classes and also all it's static members. Buf from AGP 3.5.0 all class members are removed.

Change your line to -keep class **$Properties {*;}.
This will prevent proguard/D8 to remove members of those Properties classes - this should resolve your issue.


基本的意思就是gradle在3.5.0的版本以及之后的版本,混淆规则出现了新的变化,需要将混淆规则中GreenDao中的

-keep class **$Properties


更换成

-keep class **$Properties {*;}


这是最新的处理方式,当然也可以直接回退gradle的版本也能解决这个问题
至于新规则的验证我还没有做,有兴趣的可以试试

你可能感兴趣的:(Android开发)