I wonder if itโs possible not to add the rule one after another for the library, as some libraries do not seem to mention how to configure proguard for them?
Yes, it is possible not to add rules one by one for each library that you used in your project. Try adding the following to the proguard-rules.pro file.
-keep class !com.example.myproject.** { *; }
The idea is to simply put a proguard-rules.pro with the regular expression that you use in your proguard-rules.pro .
But what's the point of using proguard if you don't mess up your code. You might want to keep some classes in your project unchanged after obfuscation. You just need to keep them like other libraries. For instance -
// I want to keep the classes in the `Models` package to remain unchanged -keep class com.example.myproject.Models.** { *; } -keepclassmembers class com.example.myproject.Model.** { *; }
In any case, itโs not very difficult to add rules one by one, since you will have more control when confusing. Here is my proguard-rules.pro . You can take a look at it.
-useuniqueclassmembernames -allowaccessmodification -keep class com.google.** { *; } -keep class com.journeyapps.** { *; } -keep class com.makeramen.** { *; } -keep class com.github.** { *; } -keep class org.apache.** { *; } -keep class com.flipboard.** { *; } -keep class com.android.** { *; } -keep class com.mikepenz.** { *; } -keep class junit.** { *; } -keep class org.mockito.** { *; } -keep class android.support.v7.widget.SearchView { *; } -keep class com.example.myproject.Models.** { *; } -keepclassmembers class com.example.myproject.Model.** { *; } -keepattributes Signature -keepattributes *Annotation* -dontwarn com.google.** -dontwarn org.apache.** -dontwarn android.support.** -dontwarn org.junit.** -dontwarn org.mockito.** -dontwarn com.makeramen.** -assumenosideeffects class android.util.Log { public static *** d(...); public static *** v(...); public static *** w(...); public static *** i(...); public static *** e(...); }
source share