为什么Proguard的保留活动类的Android? [英] Why Proguard keeps Activity class in Android?
问题描述
我已经申请的ProGuard ,以我的Android应用程序。
I have applied ProGuard to my Android application.
我用
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);
}
从后面的活动类名被ProGuard的obfusctated而有些方法是preserved,因为它们。这是可以理解的。
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.
但是,这意味着活动派生类不混乱?。它应该已经失败了,因为ProGuard的不具有 -keep类
指令为活动
,它只有 -keepclassmembers。
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.
有人可以,请解释一下,如果我可以依靠我观察行为?还是我误解了 -keepclassmembers
指令?
Can someone, please, explain, if I can rely on the behaviour I observe? Or do I misunderstand the -keepclassmembers
directive?
推荐答案
由于活动都在清单和类上市引用有会被自动保存。这是必要的,因为Android框架通过反射访问这些应用程序的入口点。
Because the activities are listed in the manifest and classes referenced there are automagically kept. This is needed because the Android framework accesses these app entry points via reflection.
从<一个href=\"http://stackoverflow.com/questions/19180434/why-proguard-processes-androidmanifest-xml\">here:
在生成过程运行该工具AAPT自动创建配置文件斌/ proguard.txt
,根据的AndroidManifest.xml
和其他XML文件。然后,构建过程传递配置文件的ProGuard。所以ProGuard的本身确实没有考虑的AndroidManifest.xml
,但AAPT + ProGuard的事情。
The build process runs the tool aapt to automatically create the configuration file
bin/proguard.txt
, based onAndroidManifest.xml
and other xml files. The build process then passes the configuration file to ProGuard. So ProGuard itself indeed doesn't considerAndroidManifest.xml
, but aapt+ProGuard do.
这篇关于为什么Proguard的保留活动类的Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!