Sayed Jalil Hassan
Sayed Jalil Hassan

Reputation: 2595

Android: Proguard rules for dependencies and modules

I have a project with a couple of modules, some jar dependencies in libs folder and some some other gradle dependencies. I am trying to build a release apk with proguard enabled but i am getting a lot of warnings during the build process for certain dependencies. e.g this:

Warning:org.codehaus.jackson.jaxrs.JacksonJsonProvider: can't find superclass or interface javax.ws.rs.ext.MessageBodyReader 

Would someone please refer a guide on how to properly define rules for the dependencies. and do i need to add rules for the modules besides the app module.

Edit:

I have added the following rule to the app build.gradle file:

-keep interface org.codehaus.jackson.** { *; }
-keep class org.codehaus.jackson.** { *; }

but i am still getting the warnings during build process.

Upvotes: 5

Views: 6239

Answers (1)

williamj949
williamj949

Reputation: 11316

I am using this rule for retrofit

-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-dontwarn com.squareup.okhttp.**

-dontwarn rx.**
-dontwarn retrofit.**
-dontwarn okio.**
-keep class retrofit.** { *; }
-keepclasseswithmembers class * {
    @retrofit.http.* <methods>;
}

and my jackson rules are

-keepattributes *Annotation*,EnclosingMethod,Signature
-keepnames class com.fasterxml.jackson.** { *; }
 -dontwarn com.fasterxml.jackson.databind.**
 -keep class org.codehaus.** { *; }
 -keepclassmembers public final enum org.codehaus.jackson.annotate.JsonAutoDetect$Visibility {
 public static final org.codehaus.jackson.annotate.JsonAutoDetect$Visibility *; }
-keep public class your.class.** {
  public void set*(***);
  public *** get*();
}

EDIT

Your library jars refer to yet more library jars (Mortbay, SLF4J, Apache Commons Logging, Log4j, ...) Adding these jars with extra '-libraryjars' options should solve the problem.If you are not refrencing them then use this rule

-dontwarn javax.management.**  
-dontwarn java.lang.management.**  
-dontwarn org.apache.log4j.**  
-dontwarn org.apache.commons.logging.** 
-dontwarn org.slf4j.**  
-dontwarn org.json.*

Upvotes: 2

Related Questions