I want to know what does mean by
-ignorewarnings
-keep class * {
public private *;
}
-keep class * {
public private protected *;
}
And what if there are some model classes there in my code have some primitive types and getter setters. I don't want to obfuscate there names specially "keys" what rule I should use for them?
ProGuard also optimizes the bytecode, removes unused code
instructions, and obfuscates the remaining classes, fields, and
methods with short names.
-keep public class packageName.ParticularClassName.** { *; }
#Keep annotation to the code you want to keep. Adding #Keep on a class
keeps the entire class as-is. Adding it on a method or field will keep
the method/field (and it's name) as well as the class name intact.
Read Customize which code to keep.
Related
I have some dagger classes in an android SDK that need to be protected from minification and obfuscation when creating and publishing the release version. I protect those by using custom proguard rules around the #Module and #DaggerGenerated annotations.
-keep #dagger.Module public class * { public <methods>; }
-keep #dagger.internal.DaggerGenerated public class * {public <methods>;}
Some of those classes have companion objects that should also be protected. At the moment, I protect them by annotating the companions specifically with #Keep. Is there a way to specify a proguard rule to automatically keep the companion?
I tried a few variations such as the one below but none of them got the job done.
-keep #dagger.Module class *$Companion { *; }
Perhaps not an ideal solution, but you could instead try to keep an entire package instead of individual files, using something like:
-keep class com.foo.bar.** { *; }
this way, you'll be covering any companion objects found here as well
my data is saved to firebase this way:
a: "Tom"
b: "26"
...
I know that in order to save it with the correct keys ("mName" instead of "a", "mAge" instead of "b" and so on) I have to add the next lines to my proguard according to the documentation
https://firebase.google.com/docs/database/android/start/#proguard
# Add this global rule
-keepattributes Signature
# This rule will properly ProGuard all the model classes in
# the package com.yourcompany.models. Modify to fit the structure
# of your app.
-keepclassmembers class com.yourcompany.models.** {
*;
}
my questions is:
Assuming that my package name is com.testing, should the added lines look like these?
-keepattributes Signature
-keepclassmembers class com.testing.models.** {
*;
}
OR the second line should be without the "models"? like this:
-keepclassmembers class com.testing.** {
Moreover, if I have only 1 global class named Data that I save to firebase, can I just keep these class members specifically? or I must act as shown above..
yes, it will look like this
-keepattributes Signature
-keepclassmembers class com.testing.models.** { *; }
If you have only one model class called Data, add the following lines instead
-keepattributes Signature
-keep class com.testing.models.Data { *; }
I am trying to prevent proguard from obfuscating interface (or abstract class) methods parameters.
Lets say I have this interface in my lib :
package com.mypackage;
public interface MyLibListener {
void onSomething(boolean success, String message);
}
And this proguard file :
-keepparameternames
-keep interface com.mypackage.MyLibListener {
*;
}
Then I assemble release and I get :
package com.mypackage;
public interface MyLibListener {
void onSomething(boolean var1, String var2);
}
Same thing with abstract classes or using #Keep annotations. Obfuscation option keepparameternames seems to work only for regular classes. Any idea? Thanks!
(related SO : How to not obfuscate interface methods & it's parameters using Progaurd in android? and Proguard keep interface method variable names)
Add following ProGuard options to your configuration.
-keepattributes MethodParameters
If your class file hava method parameters metadata (compiled using Java8 -parameters or etc...)`, ProGuard will keep the metadata.
To keep all interface methods:
-keep interface * {
<methods>;
}
To keep all public and protected methods, which could be used by reflection:
-keepclassmembernames class * {
public protected <methods>;
}
While I don't understand, why one would want to keep abstract classes, which cannot be instanced anyway, therefore it's pointless to keep & know their names. In theory, one could exclude all that is not abstract with rules which start with -keep !abstract, but that's kind of redundant.
Your proguard file may lack some -keepattributes, especially a -keepattributes Signature.
Check this example proguard configuration for a library from the proguard documentation to look for ideas.
I want to obfuscate a class and its public method. I am using following code to obfuscate :
-keep class !com.supermentor.ApiService { *; }
but this doesn't work. Does anyone has idea? How to obfuscate only one class and its public methods.
This worked for me:
-keep class !com.supermentor.ApiService,** { *; }
But be aware order is important, firs describe what you want to exclude and then what you want to keep. In this example, you want to obfuscate ApiService and you want to everything else.
As above.
My ProGuard config is
-keepclassmembers public class myApp.interfaces.**
-keepclasseswithmembernames public class myApp.interfaces.**
-keepattributes Signature
-keepparameternames
Really new to this and no real idea what I'm doing.
What I'm trying to achieve is to make Proguard not change the method and variable names of all Classes inside myApp.interfaces.*. If they want to rearrange some algo stuff to optimise it or whatever, it's fine. As long as the names are not changed.
This must be done because of the Serializable issue between server and client.
Simply use:
-keep class myApp.interfaces.** { *; }
It will not touch the class or its members. If you get errors / warnings, Rebuild the project.