Why does ProGuard support the onCreate () method?

I try to wrap my head around this, but I just don’t understand why this happens: according to the proguard.cfg file, by default I define the following rule:

-keep public class * extends android.app.Activity 

as I understand it, this means: save the Activity class as an entry point, but feel free to shorten / obfuscate / optimize anything inside it (otherwise I would have to use, for example, the <methods> template to save methods too, right? )

Now my test activity is as follows:

 public class MyActivity extends Activity { public void onCreate(Bundle savedInstanceState) { ... } public void unusedMethod() { } } 

If I now export a signed APK and call ProGuard, it will remove unusedMethod as expected, but it will save the onCreate method, rather than obfuscate its name. Why is this?

+6
source share
1 answer

Your understanding of the settings is correct. However, ProGuard cannot delete or rename your onCreate method because it overrides the onCreate method in android.app.Activity. Renaming will break the application. Methods that do not override library methods, such as unusedMethod , can be safely deleted, inserted, or at least renamed.

Method M should be renamed if you did not specify the -keep option for it. You can verify this with the -whyareyoukeeping option.

+9
source

Source: https://habr.com/ru/post/887549/


All Articles