Should I keep android.support.v4.app.Fragment and its derived classes when building a release version of my app?

夙愿已清 提交于 2019-12-07 06:25:59

问题


I read this answer and undestood why I should keep names of my services, activities, and custom views. But should I keep my classes which derive from android.support.v4.app.Fragment?

I also took a look at the defualt Proguard config file %SDK_DIR%\sdk\tools\proguard\proguard-android.txt, and there were no rules regarding fragments.


回答1:


The main reason why you would need to keep a class, is because it is accessed via reflection.

Fragments are normally not accessed via reflection, so you don't have to keep them.

Except if you reference them directly in layout files (because parsing layout files uses reflection).




回答2:


As others have already pointed out, the main reason to keep UI elements like Fragments from being obfuscated is because they are referenced from other resources that are not processed by ProGuard, e.g. layout files.

If you would be using DexGuard you could also obfuscate Fragments and other UI classes as DexGuard will process all application resources together, allowing it to modify class names whereever they are used (except when used via reflection of course).



来源:https://stackoverflow.com/questions/37501132/should-i-keep-android-support-v4-app-fragment-and-its-derived-classes-when-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!