What are the recommended ProGuard rules for Smack 4.1?
Asked Answered
C

2

10

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?

Campagna answered 16/4, 2015 at 15:10 Comment(0)
P
8

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!

Picaresque answered 17/4, 2015 at 10:55 Comment(1)
does this answer applies for 4.2.x?Alidia
S
1

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.

Spermogonium answered 2/7, 2015 at 15:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.