user45678 user45678 -4 years ago 86
Android Question

Errors while building signature build with Proguard

While using ProGuard, I am getting io warnings and errors. I have set

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

How to resolve io errors

Answer Source

Add Proguard rules for the libraries you are using. From the errors I think you need rules for Realm and Gson. Here is it

# Proguard Configuration for Realm (
# For detailed discussion see:!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** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class** { *; }

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

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

PS: Instead of com.yourapppackagetomodelclass.realm use your package where RealmObject classes are stores

UPDATE For IBM warnings you can check for their proguard rules online and if not available then use like this

-keepclassmembers** { *; }
-keepclassmembers ibm.mce.sdk.plugin.inapp.** { *; }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download