简体   繁体   English

启用proguard后,Realm中的ClassNotFoundException

[英]ClassNotFoundException in Realm after enabling proguard

I am getting an exception: 我有一个例外:

Caused by: java.lang.ClassNotFoundException: Didn't find class "io.realm.Realm" 原因:java.lang.ClassNotFoundException:找不到类“ io.realm.Realm”

In build.gradle minifyEnabled true. 在build.gradle中,minifyEnabled为true。

proguard-rules.pro: proguard-rules.pro:

-keep class io.realm.annotations.RealmModule -keep类io.realm.annotations.RealmModule

-keep @io.realm.annotations.RealmModule class * -keep @ io.realm.annotations.RealmModule类*

-keep class io.realm.internal.Keep -keep类io.realm.internal.Keep

-keep @io.realm.internal.Keep class * -keep @ io.realm.internal.Keep类*

-dontwarn javax.** -dontwarn javax。**

-keep class io.realm.{ *; -保持io.realm类。{*; } }

-keepnames public class * extends io.realm.RealmObject -keepnames公共类*扩展io.realm.RealmObject

-keep public class * extends io.realm.RealmObject { *; -keep公共类*扩展io.realm.RealmObject {*; } }

Any idea? 任何想法?

It seems that you'll have to replace this rule: 看来您必须替换此规则:

-keep class io.realm.{ *; }

With this one: 有了这个:

-keep class io.realm.** { *; }

Everything else that starts with io.realm can then be removed. 然后可以删除以io.realm开头的所有其他内容。

Why? 为什么? The first rule you have here is invalid. 您在此处拥有的第一条规则无效。 The second one will keep everything in io.realm including any sub-packages, methods and fields. 第二个将所有内容保留在io.realm中,包括任何子包,方法和字段。 This means that it will override all of the other rules. 这意味着它将覆盖所有其他规则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM