This is my class:
package com.tools.app.holiday; public class Holiday { private String name; private Calendar dateFrom = Calendar.getInstance(); private Calendar dateTo = Calendar.getInstance(); ...
I can keep these private fields by putting the following in my ProGuard rules file:
-keepclassmembers class com.tools.app.holiday.Holiday { private java.lang.String name; private java.util.Calendar dateFrom; private java.util.Calendar dateTo; }
But I'd prefer not to have to specify each field individually. How can I do this?
P.S. I stole most of this from Proguard keep classmembers because that question was close to what I'm asking.
ProGuard is a command-line tool that reduces app size by shrinking bytecode and obfuscates the names of classes, fields and methods. It's an ideal fit for developers working with Java or Kotlin who are primarily interested in an Android optimizer.
To fix errors and force R8 to keep certain code, add a -keep line in the ProGuard rules file. For example: -keep public class MyClass. Alternatively, you can add the @Keep annotation to the code you want to keep. Adding @Keep on a class keeps the entire class as-is.
Android Studio adds the proguard-rules.pro file at the root of the module, so you can also easily add custom ProGuard rules specific to the current module. You can also add ProGuard files to the getDefaultProguardFile directive for all release builds or as part of the productFlavor settings in the build.
According to ProGuard documenation the wildcard <fields>
matches any field. Thus it should be something like:
-keepclassmembers class com.tools.app.holiday.Holiday { private <fields>; }
If you want to preserve private fields in all classes use:
-keepclassmembers class * { private <fields>; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With