Integrating Smack with Android Studio project for chat application

I am trying to implement a chat messenger using ejabberd server and smack library but having a hard time to integrate all the jars and dependencies of smack. I am using android Studio.

My build.gradle(module):

  • How to combine Cordova, Crosswalk and Ionic framework
  • Trouble connecting to LG phone with adb (Mac OS X 10.7.5)
  • Android & Robotium - Test activity that expects an extra?
  • java.lang.NoClassDefFoundError:$layout error when using facebook sdk jar
  • Setting Android Toolbar Background and Text Colors in Android Studio 1.4.1
  • How to register this tablet to Ubuntu udev list?
  • apply plugin: ''
        android {
            compileSdkVersion 22
            buildToolsVersion "22.0.1"
            defaultConfig {
                applicationId "com.example.nit.xmppclient"
                minSdkVersion 18
                targetSdkVersion 22
                versionCode 1
                versionName "1.0"
            buildTypes {
                release {
                    minifyEnabled false
                    proguardFiles getDefaultProguardFile('proguard-android.txt'), ''
        dependencies {
            compile fileTree(dir: 'libs', include: ['*.jar'])
            compile ''
            compile "org.igniterealtime.smack:smack-android:4.1.0"
            compile "org.igniterealtime.smack:smack-tcp:4.1.0"
            compile "org.igniterealtime.smack:smack-android-extensions:4.1.0"
            compile 'org.ogce:xpp3:1.1.6'

    Firstly I was getting XMLpullparser error then I added xpp3. But after I added xpp3 I am getting

    Error:Gradle: Execution failed for task ':app:preDexDebug'.
    > org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-7-openjdk-amd64/bin/java'' finished with non-zero exit value 1


    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    buildscript {
        repositories {
        dependencies {
            classpath ''
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
    allprojects {
        repositories {
            maven {
                url ''


    How to remove the error or what can be the cause of error. I might be missing some dependency ?

    Using smock will increase the app-size. can I acheive IM without using any library and writing server side code instead.
    Like using ejabberd library for node-js and the android app talking to nodejs instead of ejabberd?

    And yes I more thing :

    public class XMPPClient {
        private static int port = 5222;
        private static String host = "my-ip";
        private static String service = "";
        static XMPPTCPConnectionConfiguration conf = XMPPTCPConnectionConfiguration.builder()
        static XMPPTCPConnection connection = new XMPPTCPConnection(conf);
        public static void register(String username, String password) throws SmackException.NotConnectedException, XMPPException.XMPPErrorException, SmackException.NoResponseException {
            AccountManager accountManager = AccountManager.getInstance(connection);
        public static  void main (String args[]) throws SmackException.NotConnectedException, XMPPException.XMPPErrorException, SmackException.NoResponseException {
            register("user", "password");

    I am getting the error when i am running the XMPPClient class

  • ViewDragHelper - Child layout changes ignored while dragging
  • android View with View.GONE still receives onTouch and onClick
  • CollapsingToolbarLayout without shadow in expanded state
  • How can one know if an activity is started without a transition?
  • Android - width and height of bitmap without loading it
  • How to programmatically create and read WEP/EAP WiFi configurations in Android?
  • 3 Solutions collect form web for “Integrating Smack with Android Studio project for chat application”

    It seems you need to add multidex support. Add multidex support in your app’s build.gradle file

     android {
      compileSdkVersion 21
     buildToolsVersion "21.1.0"
    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 21
        // Enabling multidex support.
        multiDexEnabled true
    dependencies {
    compile ''

    If one does what’s done in the question he/she will be able to integrate the library.

    I was just running the file not the whole project, this might sound a silly mistake but after building the project everything worked fine.

    try to change your dependencies and build with gradles

    compile 'org.igniterealtime.smack:smack-android:4.1.6'
    compile 'org.igniterealtime.smack:smack-tcp:4.1.6'
    compile 'org.igniterealtime.smack:smack-im:4.1.6'
    compile 'org.igniterealtime.smack:smack-extensions:4.1.6'
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.