I'm trying to wrap my head around this, but I simply don't understand why this is happening: As per the default proguard.cfg file, I define the following rule:
-keep public class * extends android.app.Activity
as far as I understand, this means: keep any Activity
class as an entry point, but feel free to shrink/obfuscate/optimize anything inside it (otherwise I'd have to use e.g. the <methods>
wildcard to preserve methods, too, right?).
Now my test Activity looks like this:
public class MyActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
...
}
public void unusedMethod() {
}
}
If I now export a signed APK, and ProGuard is invoked, it will remove unusedMethod
as expected, but it will keep the onCreate
method and not obfuscate its name. Why is that?
Your understanding of the configuuration options is correct. However, ProGuard can't remove or rename your onCreate
method, because it overrides the onCreate method in android.app.Activity. Renaming it would break the application. Methods that don't override library methods, like unusedMethod
, can safely be removed, inlined, or at least renamed.
The method M
should be renamed, unless you are specifying some -keep option for it. You can check that with the option -whyareyoukeeping
.
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