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 (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: 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 com.ibm.mce.sdk.adm.** { *; }
-keepclassmembers ibm.mce.sdk.plugin.inapp.** { *; }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download