How to apply Proguard to Android library with maven?

Hello, I am struggling in applying proguard for android library,… The problem is that, I need to keep only 2 folders inside of a library, everything else should be minimized. The problem is that, I can’t make it work successfully. I tried various ways, but if client does not enable proguard, the code of library is clear and visible, just many Red colored, not found classes. How should I always ensure that my library is obscured ?

This is my library gradle and proguard setup(What am I doing wrong?):

-keepattributes InnerClasses
-keep public class com.test.test.initialization** {
  public protected *;
}
-keep public class com.test.test.models** {
  public protected *;
  public static **[] values();
      public static ** valueOf(java.lang.String);
}
-keep public class com.test.test.additional.enums** {
  public protected *;
  public static **[] values();
      public static ** valueOf(java.lang.String);
}
-keepclassmembers enum * { *; }
-keepclassmembers enum com.test.test.** { *; }
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}
-dontwarn okhttp3.internal.platform.*
-dontwarn okio.**
-dontwarn retrofit2.Platform$Java8
-dontwarn javax.annotation.Nullable
-dontwarn javax.annotation.**
-dontnote retrofit2.Platform
-dontwarn retrofit2.Platform$Java8
-verbose

App cannot access some fragments, but can access MainActivity, which is not obscured and methods are visible

My gradle:

 buildTypes {
        release {
            debuggable false
            useProguard true
            minifyEnabled true
      
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

I am publishing library with Maven, with novoda:bintray-release plugin

Also I still can’t properly keep enum values, it crashed app in some places.

@macsimus Can you please help with this when you get a chance? Thank you - much appreciated! :]

Hi @wellbranding thank you for the question. If possible, please work your way through our tutorial Getting Started with ProGuard. There are some good tips about debugging ProGuard issues that will hopefully help you diagnose the problem you are seeing. For example, taking a look at the output files produced by ProGuard such as output.txt and seeds.txt.

You have some pretty expansive keep rules. If you’ve not already, I recommend removing them all and then walking through them one-by-one to see where you run into issues when you build and run the app. I hope this helps and thanks again.

This topic was automatically closed after 166 days. New replies are no longer allowed.