Search code examples
androidrealmproguardparcelableparceler

Proguard with Parceler and Realm


I'm using Realm and Parceler and everything is working fine but when I enable the Proguard I'm getting an error when doing:

Parcels.wrap(obj)

I'm getting the following error:

org.parceler.ParcelerRuntimeException: Unable to find generated Parcelable class for io.realm.g, verify that your class is configured properly and that the Parcelable class io.realm.g$$Parcelable is generated by Parceler.

Although I have configured the proguard rules like:

##---------------Begin: proguard configuration for realm  ----------
-keep class io.realm.annotations.RealmModule
-keep @io.realm.annotations.RealmModule class *
-keep class io.realm.internal.Keep
-keep @io.realm.internal.Keep class * { *; }
-dontwarn javax.**
-dontwarn io.realm.*
##---------------End: proguard configuration for realm  ----------
##---------------Begin: proguard configuration for Parcel  ----------
-keep interface org.parceler.Parcel
-keep @org.parceler.Parcel class * { *; }
-keep class **$$Parcelable { *; }
-keep class org.parceler.Parceler$$Parcels
-keep @org.parceler.Parcel class * { *; }
-keep class *$$Parcelable { *; }
##---------------End: proguard configuration for Parcel  ----------

The object I'm trying to parcel looks like:

@Parcel(implementations = { ContentRealmProxy.class },
        value = Parcel.Serialization.BEAN,
        analyze = { Content.class })
public class Content extends RealmObject {
    ....
}

Thank in advance


Solution

  • You can add this and see if it helps:

    #realm
    -keepnames public class * extends io.realm.RealmObject
    -keep @io.realm.annotations.RealmModule class *
    -keep class io.realm.** { *; }
    -dontwarn javax.**
    -dontwarn io.realm.**
    

    I think the issue is that while you keep the names of your RealmObjects, you don't actually keep the names of your Realm proxy classes.

    So this line

    -keepnames public class * extends io.realm.RealmObject
    

    Should be enough on its own.