I noticed that the “template” proguard.cfg always contains the following:
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
Why these particular classes and not others?
Is this the complete list of classes that must not be “optimized out” by ProGuard?
In short, those classes are in the proguard.cfg template because those classes can be declared in the AndrodiManifest.xml.
Consider this minimal application:
CustomTextView.java:
ExampleActivity.java:
AndroidManifest.xml:
Now, without the line
in the proguard.cfg file, proguard might be tempted to rename
ExampleActivitytoA. It does not know anything about AndroidManifest.xml though, so it will not touch the manifest. Since the Android OS uses class names declared in the application manifest to start an application, the Android OS will try to instantiateExampleActivity, but that class won’t exist since proguard renamed it!In the case of
CustomTextView, it’s fine for proguard to rename it to sayB, because the name of the class is not important since it is not declared in the manifest, only referenced by code that proguard will update when it changes the class name ofCustomTextView.In one way or another, all classes referenced from the template proguard.cfg file can be declared in the manifest, so proguard must not touch them.