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: com.facebook.android.R$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: '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

  • 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 '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.