Give back my XMPP in Android!

Since the release of the Android SDK 1.0, people (including me) have been complaining about the lack of connectivity for the very convenient Smack API to talk to Googles GTalk servers following http://davanum.wordpress.com/2007/12/31/android-just-use-smack-api-for-xmpp/, see here.

However, yesterday @Øredev, I met Mike Jennings from the Android team and together we looked into this problem over a beer in the Oracle booth. Looking into the current SVN source at http://svn.igniterealtime.org/svn/repos/smack/trunk/source, it seemed that a fast hack to get things working (especiallly the keystore problem on the device) would be to simply disable SSL negotiation.This does of course not work for SSL stuff, but it gets you going and it is enough for talk.google.com:5222. It is enough to just disable SSL negotiation by hardcoding it away in the ConnectionConfiguration.java, and comment out everything related to java.beans and other packages that are not present on the Android platform to get things working.

After doing that, voila things started to work and I am now happily logging in programatically via SVN Smack again!

Thanks Mike for the hints, help and a great BouncingBall application!

For anyone intersted, I am attaching the patch.

/peter neubauer

smackdiff

11 Comments

  1. Chunyen Liu

    Thanks, Peter. I think I found what I need. Now I need to get the Smack source and make a patched version myself.

  2. Win

    Hi Peter,

    Are you using smack 3.1 ? If not, which version are you using?

  3. Peter Neubauer

    Hi Win,
    yes, I think this was the 3.1 version of Smack from the SVN. Have not check lately, let me know if you require something and I will try to help you!

  4. Win

    Peter,

    Thanks for the reply. I have what I need for that post but I still need more help (I am new to the development.) :). I asked if the smack was 3.1 cause when I downloaded 3.1 and tried your patch, there were still a lot of unresolved issues. It is the MXParser(); from line like this “XmlPullParser parser = new MXParser(); ” in ProviderManager . I have checked Davanum’s blog and one user mentioned that he got 3.1 working and can be emailed for the patch and source. So I emailed him and he sent me the patched jar and source (I assume that he use your patch and add jar of kxml2-2.3.0.jar and update the lines to XmlPullParser parser = new KXmlParser(); ) So I try his source and Davanum’s XMPPclient, it works. Some people on Davanum’s blog complain about XMPPClient not working on G1 or 1.5 emulator. Well, Both Davanum’s smack.jar and my recently acquired smack work on all the devices:G1 with 1.5 and 1.5 emulator also. The difference is that if I use Davanum’s smack Jar (which I doubt is not 3.1), the resource for the client is Smack+Gibberish (total is about 13 character) e.g “SmackA456D123” with the 3.1 I have, the resource is simply “Smack” , like it is hard coded in XMPPconnection.java
    public void login(String username, String password) throws XMPPException {
    login(username, password, “Smack”);
    }
    Ok, now I get it working, what else do I need help for? Well, there are a few, I don’t know if you have time or not tho :)

    First the kxmlparser has spewed out a lot of worrying debug messages, I don’t think hat they are harmful but I worry for the performance and memory footprint. Here it is :

    D/installd( 543): DexInv: — BEGIN ‘/data/app/vmdl61931.tmp’ —
    D/dalvikvm( 2685): DexOpt: ‘Lorg/xmlpull/v1/XmlPullParser;’ has an earlier definition; blocking out
    D/dalvikvm( 2685): DexOpt: ‘Lorg/kxml2/io/KXmlParser;’ has an earlier definition; blocking out
    D/dalvikvm( 2685): DexOpt: ‘Lorg/xmlpull/v1/XmlSerializer;’ has an earlier definition; blocking out
    D/dalvikvm( 2685): DexOpt: ‘Lorg/kxml2/io/KXmlSerializer;’ has an earlier definition; blocking out
    D/dalvikvm( 2685): DexOpt: ‘Lorg/kxml2/kdom/Node;’ has an earlier definition; blocking out
    D/dalvikvm( 2685): DexOpt: ‘Lorg/kxml2/kdom/Document;’ has an earlier definition; blocking out
    D/dalvikvm( 2685): DexOpt: ‘Lorg/kxml2/kdom/Element;’ has an earlier definition; blocking out
    D/dalvikvm( 2685): DexOpt: ‘Lorg/kxml2/wap/Wbxml;’ has an earlier definition; blocking out
    D/dalvikvm( 2685): DexOpt: ‘Lorg/kxml2/wap/WbxmlParser;’ has an earlier definition; blocking out
    D/dalvikvm( 2685): DexOpt: ‘Lorg/kxml2/wap/WbxmlSerializer;’ has an earlier definition; blocking out
    D/dalvikvm( 2685): DexOpt: ‘Lorg/kxml2/wap/syncml/SyncML;’ has an earlier definition; blocking out
    D/dalvikvm( 2685): DexOpt: ‘Lorg/kxml2/wap/wml/Wml;’ has an earlier definition; blocking out
    D/dalvikvm( 2685): DexOpt: ‘Lorg/kxml2/wap/wv/WV;’ has an earlier definition; blocking out
    D/dalvikvm( 2685): DexOpt: ‘Lorg/xmlpull/v1/XmlPullParserException;’ has an earlier definition; blocking out
    D/dalvikvm( 2685): DexOpt: ‘Lorg/xmlpull/v1/XmlPullParserFactory;’ has an earlier definition; blocking out
    I/dalvikvm( 2685): DexOpt: not resolving ambiguous class ‘Lorg/xmlpull/v1/XmlPullParser;’
    I/dalvikvm( 2685): DexOpt: not resolving ambiguous class ‘Lorg/kxml2/io/KXmlParser;’
    I/dalvikvm( 2685): DexOpt: not resolving ambiguous class ‘Lorg/xmlpull/v1/XmlPullParser;’
    I/dalvikvm( 2685): DexOpt: not resolving ambiguous class ‘Lorg/kxml2/io/KXmlParser;’
    I/dalvikvm( 2685): DexOpt: not resolving ambiguous class ‘Lorg/xmlpull/v1/XmlPullParser;’
    D/dalvikvm( 2685): DexOpt: not verifying ‘Lorg/xmlpull/v1/XmlPullParser;’: multiple definitions
    D/dalvikvm( 2685): DexOpt: not verifying ‘Lorg/kxml2/io/KXmlParser;’: multiple definitions
    D/dalvikvm( 2685): DexOpt: not verifying ‘Lorg/xmlpull/v1/XmlSerializer;’: multiple definitions
    D/dalvikvm( 2685): DexOpt: not verifying ‘Lorg/kxml2/io/KXmlSerializer;’: multiple definitions
    D/dalvikvm( 2685): DexOpt: not verifying ‘Lorg/kxml2/kdom/Node;’: multiple definitions
    D/dalvikvm( 2685): DexOpt: not verifying ‘Lorg/kxml2/kdom/Document;’: multiple definitions
    D/dalvikvm( 2685): DexOpt: not verifying ‘Lorg/kxml2/kdom/Element;’: multiple definitions
    D/dalvikvm( 2685): DexOpt: not verifying ‘Lorg/kxml2/wap/Wbxml;’: multiple definitions
    D/dalvikvm( 2685): DexOpt: not verifying ‘Lorg/kxml2/wap/WbxmlParser;’: multiple definitions
    D/dalvikvm( 2685): DexOpt: not verifying ‘Lorg/kxml2/wap/WbxmlSerializer;’: multiple definitions
    D/dalvikvm( 2685): DexOpt: not verifying ‘Lorg/kxml2/wap/syncml/SyncML;’: multiple definitions
    D/dalvikvm( 2685): DexOpt: not verifying ‘Lorg/kxml2/wap/wml/Wml;’: multiple definitions
    D/dalvikvm( 2685): DexOpt: not verifying ‘Lorg/kxml2/wap/wv/WV;’: multiple definitions
    D/dalvikvm( 2685): DexOpt: not verifying ‘Lorg/xmlpull/v1/XmlPullParserException;’: multiple definitions
    D/dalvikvm( 2685): DexOpt: not verifying ‘Lorg/xmlpull/v1/XmlPullParserFactory;’: multiple definitions
    D/dalvikvm( 2685): DexOpt: load 463ms, verify 1618ms, opt 254ms
    D/installd( 543): DexInv: — END ‘/data/app/vmdl61931.tmp’ (success) —

    Next, I notice that Smack provide a complete package for Jabber including package that will handle proxy. I don’t think that proxy is needed for android. I don’t know what else is not needed in android. I would like to know how to get rid of unnecessary packages safely. Again, for performance and memory footprint. It would be great if you have time to take a look into these issues. I can email you the new patched source of 3.1 if you want it to save time. Again, thanks a lot for working them on your Beer time!!! ;)

    win

  5. Cao Minh Vu

    I’ve used Smack 3.1. Now, i can chat with Gtalk server or connect to other XMPP server (using new way to port Smack to android). But i can’t using jingle library. I can’t build the jingle library on J2SE, too. Have you continued in this work? Please help me to solve this problem?
    -CMV-

  6. Win

    CMV,

    Are you aware of google voice? you should take a look into it cause there is already google voice app for android.

    win

  7. Awesome work, thanks a ton for posting this. If anyone needs help applying the patch and getting the XMPP extensions to work, I have a quick followup post here: http://bjdodson.blogspot.com/2009/07/xmpp-on-android-using-smack.html

  8. Thanks for the info and patch. Having XMPP in Android, especially using the tried and true Smack API, is great.

    Will there eventually be a way to enable SSL again?

  9. Rajesh

    How to connect facebook chat

  10. aniyan

    its not possible !!! :( especially those who shift domain from flex to android

Leave a Reply