Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does ProGuard keep the onCreate() method?

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?

like image 212
Matthias Avatar asked May 08 '11 09:05

Matthias


1 Answers

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.

like image 102
Eric Lafortune Avatar answered Sep 28 '22 07:09

Eric Lafortune