Why Proguard keeps Activity class in Android?

Viewed 9345

I have applied ProGuard to my Android application.

I'm using

android-studio/sdk/tools/proguard/proguard-android.txt

as a configuration file, changing nothing.

In this file I can see the only statement regarding Activity:

We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

It follows from that the Activities class names are obfusctated by ProGuard while some methods are preserved as they are. This is understandable.

However, in my application I then create an Activity Class from a string using

Class.forName("my.app.MyActivity")

then I start this Activity and it starts fine.

But that means Activity-derived classes are not obfuscated??. It should have failed because ProGuard does not have -keep class directive for Activity, it only has -keepclassmembers.

Can someone, please, explain, if I can rely on the behaviour I observe? Or do I misunderstand the -keepclassmembers directive?

2 Answers
Related