【问题标题】:Proguard with Parceler and Realm使用 Parceler 和 Realm 进行 Proguard
【发布时间】:2016-10-24 06:26:52
【问题描述】:

我正在使用 Realm 和 Parceler,一切正常,但是当我启用 Proguard 时,我遇到了错误:

Parcels.wrap(obj)

我收到以下错误:

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.

虽然我已经配置了 proguard 规则,例如:

##---------------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  ----------

我要打包的对象如下所示:

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

提前致谢

【问题讨论】:

    标签: android realm proguard parcelable parceler


    【解决方案1】:

    你可以添加这个,看看是否有帮助:

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

    我认为问题在于,虽然您保留了 RealmObjects 的名称,但实际上并没有保留您的 Realm 代理类的名称。

    所以这一行

    -keepnames public class * extends io.realm.RealmObject
    

    一个人应该够用了。

    【讨论】:

    • 据说只有-keepnames public class * extends io.realm.RealmObject就够了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-18
    • 1970-01-01
    相关资源
    最近更新 更多