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 do I sendBroadcast(intent) from myDialog and receive in myActivity?
  • Android: Change ActionBar Menu Items from Fragment
  • how to open a different fragment on recyclerview OnClick
  • Using tesseract on android
  • A correct way to convert byte in java to unsigned char* in C++, and vice versa?
  • Android color selector doesn't work with custom attributes
  • apply plugin: 'com.android.application'
    
        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'), 'proguard-rules.pro'
                }
            }
        }
    
        dependencies {
            compile fileTree(dir: 'libs', include: ['*.jar'])
            compile 'com.android.support:appcompat-v7:22.2.0'
    
            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'.
    > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-7-openjdk-amd64/bin/java'' finished with non-zero exit value 1
    

    build.gradle(project):

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    
    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:1.2.2'
    
    
    
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            jcenter()
            maven {
                url 'https://oss.sonatype.org/content/repositories/snapshots'
            }
            mavenCentral()
        }
    
    }
    

    Questions:

    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 = "my.com";
    
    
        static XMPPTCPConnectionConfiguration conf = XMPPTCPConnectionConfiguration.builder()
                .setServiceName(service)
                .setPort(port)
                .setHost(host)
                .setCompressionEnabled(false).build();
        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);
            accountManager.createAccount(username,password);
        }
    
        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

    Related posts:

    Why is this a memory leak
    View reuse in fragments android
    layout_gravity not working in horizontal linear layout
    Clarification regarding Android “Attribute elevation is only used in API level 21 and high...
    Android 4.2 RadioButton android:drawableLeft bug?
    which are default font comes with all android 2.1 and above
  • How to use Data Binding and Kotlin in Android Studio 3.0.0
  • Load images in Html.fromHtml in textview (http url images, Base64 url images)
  • How to run a service every day at noon, and on every boot
  • Developing a smartcard reader in Android
  • MPAndroidChart - Adding labels to bar chart
  • Google Chrome for Android remote web debugging
  • 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 'com.android.support:multidex:1.0.0'
    }
    

    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.