168

Which XMPP library would be the best choice nowadays for Android development?

  • I've been using the patched Smack library as is suggested in many other questions here in SO. However, that's a patched version of the Smack API from two years ago. And although it generally works well I'm exploring any other, more recent options.

  • I've been looking at the official Smack API and after a little research, it seems it might work just fine nowadays (although I have not tried it yet in a real application).

  • There's also another solution I came across, Beem's aSMACK library. Beem is a fairly new XMPP client for android and from what I understand they are using their own patched version of aSMACK.

  • Finally, there's aSMACK but that too hasn't been updated for quite some time (as the site suggests).

Do you have any other suggestions or can you explain why I should choose one of the above over the rest?

BlueWizard
  • 372
  • 4
  • 19
alkar
  • 5,459
  • 7
  • 27
  • 43
  • 2
    What did you go with in the end? I am trying to decide whether to use official smack or not? – Tom Jun 10 '11 at 14:29
  • @Tom: I continued using the first option and never changed to a different version because the project development was halted soon after this post. However, I am inclined to use ASmackService in the future, as mentioned below in the answer by Flow, since I like minimal. – alkar Jun 13 '11 at 19:10
  • 2
    Just a ping / note, I've re-opened this in favor of the duplicate that caused this to be closed. – Tim Post Aug 21 '11 at 17:27
  • 86
    I think that closing this question is a *big mistake*. Being involved in XMPP on Android I can tell that is the only **reliable** and **up to date** resource when it comes to the question "How can I use XMPP on Android?" on the whole net. By closing it, you take a high quality value from SO. The question was open for over a year without problems and questions that asked the same where closed as duplicates pointing to this question. I don't even see the point in closing it as "not constructive": It's based on a real world problem, involves facts and references. See also upvote and fav count. – Flow Feb 18 '12 at 10:23
  • @casperOne Could you explain why the question was closed? – Flow Feb 21 '12 at 12:04
  • @Flow See the close reason below. "Do you have any other suggestions or can you explain why I should choose..." is ultimately not constructive. – casperOne Feb 21 '12 at 12:16
  • @casperOne I [made an suggested edit](http://stackoverflow.com/suggested-edits/206074) to allow the question to be re-opened. I think there should be a least one open question about how to add XMPP to Android applications on stackoverflow. – Flow Feb 21 '12 at 13:02
  • @Flow That suggested edit isn't going to get the question reopened; there's no way that you could phrase this that wouldn't make it a list question; list questions are specifically not constructive for Stack Overflow. Stack Overflow is not about maintaining lists, but quality questions and answers (not lists disguised as Q&A). – casperOne Feb 21 '12 at 13:04
  • 2
    @casperOne So there is no way that one could ask "How can I use XMPP in Android applictions?" on stackoverflow? Sorry, but this is *ridiculous*. By thinking this way, one could close every question on stackoverflow that has more then one answer/possible solution. This question was open for over a year without anybody bothering and is the target of many similar questions closed as exact duplicates. Soon we will have a new question that takes the role of this one. Are you really willing to close all of those questions to come? – Flow Feb 21 '12 at 13:31
  • @casperOne The for example [here](http://stackoverflow.com/questions/392785/xmpp-and-android), [here](http://stackoverflow.com/questions/9236160/xmpp-with-android) and [here](http://stackoverflow.com/questions/5501190/implementaion-of-xmpp-into-android) – Flow Feb 21 '12 at 13:33
  • @Flow If asked in this manner, then yes. BTW, you didn't ask "How can I use XMPP in Android applications?" (which, if you didn't show any effort to show what you've done and the problem you are facing, would be closed as NARQ), you asked a completely different, non-constructive question. If you want, you can [bring this up on meta](http://meta.stackoverflow.com) if you want a fuller understanding of why this question was closed (as well as get the community's opinion on it). – casperOne Feb 21 '12 at 13:35
  • 4
    @casperOne Thanks for your patient explanations. It helps me understanding where the problem with stackoverflow is. Maybe I will bring this up on meta, but it seems that this is the majority's opinion and was discussed many times already. It just doesn't feels right, especially since it wasn't closed by votes for years. – Flow Feb 21 '12 at 13:54
  • 4
    Apart from my need for "How to use XMPP in android"the discussion between "Flow" and "casperOne" is more interesting. I wandered on internet for xmpp and in the end of the day I am here on this post which is providing me more specific informations about libraries I can use for XMPP even after TWO YEARS of OP, is definitely constructive to me and will be to hundreds of newbie for chat apps. "EVENTS" speaks more than "RULES" that "FLOW'S" point of view is correct over this questions closure. – Pankaj Oct 11 '13 at 05:22
  • It's a common practice people don't give a sh*t and close a question. like this http://goo.gl/8OQiPs it is totally unrelated but still closed. so there should be HUGE penalty in terms of deduction of user trust level and points, if some users found guilty of closing some post that should not be closed. Here Admin formed a monopoly and when they see that x has closed it so they don't give a sh*t and they just hit close maybe because they trust each other and this is the major problem, needs to be addresses otherwise there will some other counter stackoverflow website, who know :-) – AZ_ Apr 22 '14 at 03:18
  • @Flow, What's the difference between this thread and http://stackoverflow.com/q/177514/632951 ? – Pacerier Nov 29 '14 at 20:11
  • Android is not Java. It's just the same language but a different runtime. – Flow Nov 29 '14 at 21:41

7 Answers7

108

Smack

Smack is a open-source XMPP client library. Since version 4.1 it runs natively on Android. For more information have a look at the "Smack 4.3 Readme" and see the Smack project page at Ignite Realtime.

Flow
  • 23,572
  • 15
  • 99
  • 156
  • 8
    Merged Smack 3.2.0 into asmack. Check out the branches on github :) – Flow Jun 14 '11 at 18:20
  • Edited comments > hi all > I am using asmack for developing my xmpp client,I am facing a problem > When i come from 1st time login I start my chatting with user B and receiving messages from user B also that is fine.i switch off my wifi and switch on it again then programatically reconnecting my jabber server and again login my account,after reconnecting I am sending messages to user B that is fine but when user B sending me messages that messages on my side not receiving .I don't know what's is wrong with it.plz guide – aftab Jun 28 '12 at 13:32
  • hi Flow > how we can merge existing asmack with latest smack ? or it is availabel wherer from I can download asmack with latest smack ? – aftab Aug 15 '12 at 16:28
  • @aftab As stated in my answer, [asmack](https://github.com/Flowdalic/asmack) and the used [smack branch](https://github.com/Flowdalic/smack) can be found on github. Make sure to read the README's on github. – Flow Aug 15 '12 at 16:32
  • hi you have give some link to understand but now they are not available so do have any example for xmpp chat which work fine.. – J_K May 07 '13 at 07:11
  • @Flow i am using your library to implement XMPP transaction but i dont see BOSHConnection in it , where can i find that ? – Hunt May 09 '14 at 10:55
  • 3
    @J_K https://github.com/meisterfuu/SmackAndroidDemo – Alexey Feb 16 '15 at 10:25
  • is there anyone to help me about this question ? http://stackoverflow.com/questions/33452890/smack-message-listener-not-called – MHSaffari Nov 13 '15 at 18:30
  • So far I have issues with smack + the forums are dead. Still looking for an alternative – Gooey Jan 12 '16 at 21:01
6

I recently stumbled across another open-source solution: jaxmpp2

jaxmpp2 also targets Android (and Java SE). I can't really say anything else about it, because I don't use jaxmpp2 in my Android/XMPP projects. But it looks like a valid alternative to aSmack.

Flow
  • 23,572
  • 15
  • 99
  • 156
  • 1
    can you please describe any way to start with , smack library .... this is totally new for me . please make a blog or some libaray_project that guys with normal mind can understand this library properly . – Tushar Pandey Jun 19 '14 at 07:33
  • I found a tutorial on http://developer.samsung.com/android/technical-docs/Building-a-Chat-Application# which is especially good, note that there calls for some small modification due to compatibility reasons: http://stackoverflow.com/questions/23506658/begginer-asmack-error – realjin Aug 03 '14 at 13:02
3

Use qsmack for android

https://code.google.com/p/qsmack/downloads/list

Its the latest build for Android

I have worked on one to one chat, group chat, video transfer, audio transfer, last seen, change registration number... almost complete whats app. I have created lots of plugin on openfire

Jaspreet Chhabra
  • 1,431
  • 15
  • 23
3

I would like to use libstrophe and jni. Goals to use this is cross platform, simple to use and performance. libstrophe is written in c so, it easy to write android makefile since the dependency is only openssl and expat lib. In my case, I'm using openssl and expat lib from libjingle which already port to android and ios. (Just need to port gyp file to android makefile or IOS project).

Below is my android makefile



    LOCAL_PATH:= $(call my-dir)/../../libstrophe-0.8.7

    SSL_PROJECT_PATH := openssl/libs/android

    include $(CLEAR_VARS)

    LOCAL_MODULE := openssl

    OPENSSL_LIB_NAME := lib$(LOCAL_MODULE).a

    LOCAL_CFLAGS := -DL_ENDIAN \
        -DOPENSSL_THREADS \
        -DPURIFY \
        -DTERMIO \
        -D_REENTRANT \
        -DOPENSSL_NO_HW \
        -DOPENSSL_NO_GOST \
        -DOPENSSL_NO_DTLS1 \
        -DOPENSSL_NO_RDRAND \
        -DOPENSSL_NO_RSAX \
        -Wall -pipe -fno-exceptions -fno-rtti -fstrict-aliasing -mfpu=neon -mfloat-abi=softfp


    OPENSSL_PATH := openssl/openssl
    OPENSSL_PATH_INC := $(LOCAL_PATH)/openssl/openssl

    LOCAL_C_INCLUDES := \
        $(OPENSSL_PATH_INC) \
        $(OPENSSL_PATH_INC)/include \
        $(OPENSSL_PATH_INC)/crypto \
        $(OPENSSL_PATH_INC)/crypto/asn1 \
        $(OPENSSL_PATH_INC)/crypto/evp \
        $(OPENSSL_PATH_INC)/crypto/modes \
        $(LOCAL_PATH)/openssl/config/android \
        $(LOCAL_PATH)/openssl

    LOCAL_ARM_MODE := arm
    LOCAL_CFLAGS += $(LOCAL_C_INCLUDES:%=-I%) -O3 -DANDROID_NDK


    LOCAL_SRC_FILES := \
        // here is openssl file which is defined in gyp

    LOCAL_SHORT_COMMANDS := true

    include $(BUILD_SHARED_LIBRARY)


    include $(CLEAR_VARS)

    STROPHE_PATH := $(LOCAL_PATH)
    EXPAT := expat-2.1.0
    OPENSSL_PATH := openssl/openssl
    OPENSSL_PATH_INC := $(LOCAL_PATH)/openssl/openssl


    EXPAT_SRC_FILES := \
        $(EXPAT)/lib/xmlparse.c \
        $(EXPAT)/lib/xmlrole.c \
        $(EXPAT)/lib/xmltok.c

    COMMON_CFLAGS := \
        -Wall \
        -Wmissing-prototypes -Wstrict-prototypes \
        -Wno-unused-parameter -Wno-missing-field-initializers \
        -fexceptions \
        -DHAVE_EXPAT_CONFIG_H \
        -DLOGGING -DANDROID \



    COMMON_C_INCLUDES += \
        $(LOCAL_PATH)/$(EXPAT)/lib \
        $(STROPHE_PATH) \
        $(STROPHE_PATH)/src \
        $(OPENSSL_PATH_INC) \
        $(OPENSSL_PATH_INC)/include \
        $(OPENSSL_PATH_INC)/crypto \
        $(OPENSSL_PATH_INC)/crypto/asn1 \
        $(OPENSSL_PATH_INC)/crypto/evp \
        $(OPENSSL_PATH_INC)/crypto/modes \
        $(LOCAL_PATH)/openssl/config/android \
        $(LOCAL_PATH)/openssl \
        ../android/jni


    STROPHE_SRC_FILES := src/auth.c \
        src/conn.c \
        src/ctx.c \
        src/event.c \
        src/handler.c \
        src/hash.c \
        src/jid.c \
        src/md5.c \
        src/sasl.c \
        src/scram.c \
        src/sha1.c \
        src/snprintf.c \
        src/sock.c \
        src/stanza.c \
        src/thread.c \
        src/tls_openssl.c \
        src/util.c \
        src/parser_expat.c \
        src/message.c \
        src/presence.c \
        src/roster.c


    JNI_SRC_FILES := ../android/jni/strophe-jni.c

    ifeq ($(TARGET_ARCH),arm)
        LOCAL_SDK_VERSION := 8
    else
        LOCAL_SDK_VERSION := 9
    endif

    LOCAL_ARM_MODE := arm
    LOCAL_SHORT_COMMANDS := true
    LOCAL_SYSTEM_SHARED_LIBRARIES := libc
    LOCAL_SHARED_LIBRARIES := openssl

    LOCAL_SRC_FILES := $(EXPAT_SRC_FILES)
    LOCAL_SRC_FILES += $(STROPHE_SRC_FILES)
    LOCAL_SRC_FILES += $(JNI_SRC_FILES)

    LOCAL_CFLAGS += $(COMMON_CFLAGS)
    LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
    LOCAL_CFLAGS += $(LOCAL_C_INCLUDES:%=-I%) -O3 -DANDROID_NDK
    LOCAL_C_INCLUDES += $(COMMON_C_INCLUDES)


    LOCAL_MODULE:= libnativeclient
    LOCAL_MODULE_TAGS := optional

    include $(BUILD_SHARED_LIBRARY)


nguyentran
  • 458
  • 2
  • 14
1

You can use Tigase JaXMPP Client Library - it's very versatile and you can use it for both JavaSE applications and for Android development. It's actively developed and Tigase Messenger for Android (Play Store) is based on it.

There is a Basic library documentation wiki page with a couple of examples and for details you should refere to javadocs

DzaveD
  • 13
  • 4
Wojtek
  • 1,845
  • 1
  • 14
  • 33
0

Using Smack 4.1 Readme and Upgrade Guide

Using Android studio 2.3, Recently I have implemented a demo in a very simple way.

-> Just Add gradle dependency in app level gradle as below

compile "org.igniterealtime.smack:smack-tcp:4.1.0"

// Optional for XMPPTCPConnection

compile "org.igniterealtime.smack:smack-android-extensions:4.1.0"

-> Configure Connection Configuration
NOTE : Call this in AsyncTask or in other background thread

 XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
                    .setUsernameAndPassword("Your Username here", "Your Password here")
                    .setHost("Host name here")
                    .setServiceName("Your service name here")
                    .setPort(Your port number here)
                    .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled) //Disable or enable as per development mode
                    .setDebuggerEnabled(true) // to view what's happening in detail
                    .build();

-> Use isConnected() and isAuthenticated()

-> Use ChatManager for add chatListener.

Tarun Dholakiya
  • 829
  • 1
  • 10
  • 16
0

You can use QuickBlox1 for free.

It provides XMPP server out of the box with lots of features, you can read about features there http://quickblox.com/developers/Chat

Here is an example how to start using QuickBlox with aSmack library http://quickblox.com/developers/Android_XMPP_Chat_Sample

Faisal Shaikh
  • 3,900
  • 5
  • 40
  • 77