I have a bunch of classes that use e.g. an @Singleton annotation like so
@Singleton public class ImageCache
that I would like to keep. How can I configure a proguard -keep statement so it applies to all classes that have that annotation.
Btw in terms of context I need this for an app using Roboguice on Android, which is why I added the tags. Might help others.
-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.
-keep Specifies classes and class members (fields and methods) to be preserved as entry points to your code. For example, in order to keep an application, you can specify the main class along with its main method. In order to process a library, you should specify all publicly accessible elements.
Simply by enabling Proguard, we at Gradeup reduced our app size by a whooping 40%! It obfuscates the code, which means that it renames classes, fields, and methods with semantically obscure names that, in addition to making the codebase smaller and more efficient, also makes it difficult to reverse engineer the app.
The getDefaultProguardFile() refers default file “proguard-android. txt” which gets from the Android SDK tools/proguard/ folder. You can also use “proguard-android-optimize. txt” file for more code shrinking located on the same folder.
ProGuard is based on a java-like configuration with wild-cards. It does require fully qualified class names. This should work:
-keep @com.google.inject.Singleton public class *
First define an annotation
public @interface DoNotStrip {}
Then put this in proguard.cfg:
-keep,allowobfuscation @interface com.something.DoNotStrip # Do not strip any method/class that is annotated with @DoNotStrip -keep @com.something.DoNotStrip class * -keepclassmembers class * { @com.something.DoNotStrip *; }
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