How can I tell proguard to keep my classmembers?
I need them for JSON compatibility...
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 already tried, but it doesnt work...
-keepclassmembers class com.tools.app.holiday.Holiday
-keepclassmembers class com.tools.app.holiday.Holiday *{
private String name;
private Calendar dateFrom;
private Calendar dateTo;
}
I also implemented serialisable and did:
-keepclassmembers class * implements java.io.Serializable {
But it all doesn't keep my member names. Proguard always changes ist to a, b, c :-( What am I missing?
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.
-keepclassmembernames. This is the most permissive keep directive; it lets ProGuard do almost all of its work. Unused classes are removed, the remaining classes are renamed, unused members of those classes are removed, but then the remaining members keep their original names.
ProGuard Facts: Helps to remove unused classes, members & fields. It removes unused codes from your libraries as well. (Which means, any method or field that is not referenced anywhere will be removed by ProGuard Shrinker). Helps to reduce the build size by obfuscating the classes, methods, & fields with short names.
R8 is having a faster processing time than Proguard which reduces build time. R8 gives better output results than Proguard. R8 reduces the app size by 10 % whereas Proguard reduces app size by 8.5 %. The android app having a Gradle plugin above 3.4.
All class names must be fully qualified:
-keepclassmembers class com.tools.app.holiday.Holiday {
private java.lang.String name;
private java.util.Calendar dateFrom;
private java.util.Calendar dateTo;
}
By default, ProGuard even prints out messages if you forget this.
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