androidproguardgreendaogreendao3

App crash in release build for enabling proguard when using GreenDao


I am using GreenDao in my project, when I build the application in release mode then the app crashes. If I disable proguard (minifyEnabled false) in gradle then it's running perfectly. I have used the following rules in proguard.

### greenDAO 3
-keepclassmembers class * extends org.greenrobot.greendao.AbstractDao {
public static java.lang.String TABLENAME;
}
-keep class **$Properties

# If you do not use SQLCipher:
-dontwarn org.greenrobot.greendao.database.**
# If you do not use RxJava:
-dontwarn rx.**

The error log is as follows:

java.lang.RuntimeException: org.greenrobot.greendao.DaoException: Could not init DAOConfig
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3086)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3229)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1926)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:6981)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)

Do you have any idea why this error occurs? Thanks in advance.


Solution

  • Finally, I solved the issue by preserving all of my entity (data) classes.

    # Preserve all entity (data) classes
    -keep class com.xxx.xxx.entity.* {*;}