使用 Proguard 构建签名时出错

Errors while building signature build with Proguard

在使用 ProGuard 时,我收到 io 警告和错误。我已经设置

minifyEnabled = "true" -- I don't want this to be set to false.

如何解决 io 错误

为您正在使用的库添加 Proguard 规则。从错误中我认为你需要 Realm 和 Gson 的规则。在这里

# Proguard Configuration for Realm (http://realm.io)
# For detailed discussion see: https://groups.google.com/forum/#!topic/realm-java/umqKCc50JGU
# Additionally you need to keep your Realm Model classes as well
# For example:
-keep class com.yourapppackagetomodelclass.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.**

##---------------Begin: proguard configuration for Gson  ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }

# Prevent proguard from stripping interface information from TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

##---------------End: proguard configuration for Gson  ----------

PS:不要 com.yourapppackagetomodelclass.realm 使用您的包裹,其中 RealmObject 类 是商店

更新 对于 IBM 警告,您可以在线检查他们的 proguard 规则,如果不可用,则像这样使用

-keepclassmembers com.ibm.mce.sdk.adm.** { *; }
-keepclassmembers ibm.mce.sdk.plugin.inapp.** { *; }