What are the recommended ProGuard rules for Smack 4.1?

ε祈祈猫儿з 提交于 2019-12-06 20:01:19

问题


What are the proper ProGuard rules for Smack 4.1 when building an Android release apk?

Currently, I'm using the rules from aSmack 4.0.x from the README.asmack file on the aSmack github repository which is outdated (references old class names, and intended for 4.0.x). I could not find any references to what the proper proguard rules to use for 4.1.x are, could anyone shed light on this?


回答1:


What are the proper Proguard rules for Smack 4.1 when building an Android release apk?

Depends on what "proper" means for you.

The easiest way is likely to tell ProGuard to keep all classes and interfaces of Smack.

-keep class org.jivesoftware.smack.** { *; }
-keep class org.jivesoftware.smackx.** { *; }

Alternatively you can configure ProGuard so that it only keeps those parts of Smack that you actually use, and let ProGuard strip everything else. But to do so, you'll need a good understanding how your App uses Smack. See for example the ProGuard configuration of MAXS's Transport XMPP: https://bitbucket.org/projectmaxs/maxs/src/75efeba8d8470b89da8cd8551304bb00648e4945/transport-xmpp/proguard-project.txt?at=master#cl-20

Note that if you don't know exactly what are you doing, then Smack could behave unexpectedly or even crash. Only fine tune ProGuard if you know what you are doing!




回答2:


Actually, my experience suggests you may actually need an additional line if you are also using proguard and have minify enabled. If you get the error

java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType

Then the following config is needed instead:

-keepattributes Signature
-keep class org.jivesoftware.smack.** { *; }
-keep class org.jivesoftware.smackx.** { *; }

See: smack for android fails when using proguard for more details.



来源:https://stackoverflow.com/questions/29678908/what-are-the-recommended-proguard-rules-for-smack-4-1

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