166
votes

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?

7
What did you go with in the end? I am trying to decide whether to use official smack or not?Tom
Just a ping / note, I've re-opened this in favor of the duplicate that caused this to be closed.Tim Post
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
@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
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

7 Answers

107
votes

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.

6
votes

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.

3
votes

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

3
votes

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)


1
votes

You can use Tigase JaXMPP Client Library - it's very versatile and you can use it for both JavaSE applications as well as you 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

0
votes

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.

0
votes

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