Proguard with Parceler and Realm

断了今生、忘了曾经 提交于 2019-12-11 06:54:27

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/40211916/proguard-with-parceler-and-realm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!