Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the recommended ProGuard rules for Smack 4.1?

Tags:

proguard

smack

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?

like image 525
Ray W Avatar asked Apr 16 '15 15:04

Ray W


2 Answers

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!

like image 103
Flow Avatar answered Nov 08 '22 16:11

Flow


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.

like image 33
Steve Avatar answered Nov 08 '22 15:11

Steve