Smack 4.1.3 Crash

Hi guys, I’m getting Smack crashes consistently on various combinations of platforms and versions that it’s truly mind boggling

  1. Platforms (crash on either one of both)

a. Android SDK 22

b. Java 8

  1. Smack versions (crash either one of both)

a. Smack 4.1.3

b. Smack 4.2.0 Alpha

Code runs Smack in an independent thread, just to be safe. Despite that, Smack would crash upon instantiation of any Smack object even before any invocation of method is carried, refer source code below

Crash upon initialization of XMPPTCPConnectionConfiguration.Builder

XMPPTCPConnectionConfiguration.Builder connconfig = XMPPTCPConnectionConfiguration.builder(); //Crash here, because the rest of codes are commented out below
//connconfig.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
//connconfig.setUsernameAndPassword(strUserId+ “@” + strServer, strPassword);
//connconfig.setServiceName(strServer);
//connconfig.setHost(strServer);
//connconfig.setPort(5222);
//connconfig.setDebuggerEnabled(true);
//connconfig.setSocketFactory(SSLSocketFactory.getDefault());

/*
mConnection = new XMPPTCPConnection(config.build());
try {
mConnection.connect();
} catch (SmackException | IOException | XMPPException e) {
e.printStackTrace();
}
*/

Alternatively, Smack would crash upon initialization of

ConnectionConfiguration connconfig = new ConnectionConfiguration(strServer); //Crash here, because the rest of codes are commented out below
// connconfig.setDebuggerEnabled(true);
// XMPPConnection connection = new XMPPConnection(connconfig);

/*
try {
connection.connect();
} catch (XMPPException e) {
retStr = e.getMessage();
}

// Most servers require you to login before performing other tasks.
try {
connection.login(strUserId, strPassword);
}
catch (XMPPException e) {
retStr = e.getMessage();
}

*/

Apart from my own projects, the Xabber source codes would also crash upon initialization of Smack objects.

I couldn’t find anyone else having crashes so widespread like these - different platforms, different Smack versions, different Smack entry points. I’m stumped now for ideas, hope someone can see some light to this.

Thanks in advance!

Erhm, and the crash manifests as? Uncaught Exception? Deadlock? Segfault?

The error trace from CatLog at the point of crashing

Summary -

07-16 11:25:56.499 2146-2280/com.flameaters.boombox.boomboxap E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-136

Process: com.flameaters.boombox.boomboxap, PID: 2146

java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/naming/directory/InitialDirContext;

at org.jivesoftware.smack.util.dns.javax.JavaxResolver.(JavaxResolver.java :50)

at java.lang.Class.classForName(Native Method)

at java.lang.Class.forName(Class.java:309)

at org.jivesoftware.smack.SmackInitialization.loadSmackClass(SmackInitialization.j ava:213)

Details -

07-16 11:25:36.815 2146-2146/com.flameaters.boombox.boomboxap I/art﹕ Not late-enabling -Xcheck:jni (already on)

07-16 11:25:38.103 2146-2155/com.flameaters.boombox.boomboxap W/art﹕ Suspending all threads took: 70.280ms

07-16 11:25:38.211 2146-2162/com.flameaters.boombox.boomboxap I/art﹕ Background sticky concurrent mark sweep GC freed 1520(86KB) AllocSpace objects, 0(0B) LOS objects, 29% free, 428KB/605KB, paused 2.189ms total 170.476ms

07-16 11:25:38.320 2146-2162/com.flameaters.boombox.boomboxap W/art﹕ Suspending all threads took: 109.285ms

07-16 11:25:38.549 2146-2162/com.flameaters.boombox.boomboxap W/art﹕ Suspending all threads took: 7.683ms

07-16 11:25:38.554 2146-2162/com.flameaters.boombox.boomboxap I/art﹕ Background partial concurrent mark sweep GC freed 294(38KB) AllocSpace objects, 0(0B) LOS objects, 52% free, 466KB/978KB, paused 9.037ms total 110.603ms

07-16 11:25:38.930 2146-2170/com.flameaters.boombox.boomboxap D/OpenGLRenderer﹕ Use EGL_SWAP_BEHAVIOR_PRESERVED: true

07-16 11:25:38.946 2146-2146/com.flameaters.boombox.boomboxap D/﹕ HostConnection::get() New Host Connection established 0xb4b17050, tid 2146

07-16 11:25:38.953 2146-2146/com.flameaters.boombox.boomboxap D/Atlas﹕ Validating map…

07-16 11:25:39.129 2146-2162/com.flameaters.boombox.boomboxap W/art﹕ Suspending all threads took: 7.879ms

07-16 11:25:39.136 2146-2162/com.flameaters.boombox.boomboxap I/art﹕ Background partial concurrent mark sweep GC freed 817(47KB) AllocSpace objects, 0(0B) LOS objects, 37% free, 866KB/1378KB, paused 10.567ms total 76.061ms

07-16 11:25:39.404 2146-2170/com.flameaters.boombox.boomboxap D/﹕ HostConnection::get() New Host Connection established 0xb4b17320, tid 2170

07-16 11:25:39.458 2146-2170/com.flameaters.boombox.boomboxap I/OpenGLRenderer﹕ Initialized EGL, version 1.4

07-16 11:25:39.494 2146-2170/com.flameaters.boombox.boomboxap D/OpenGLRenderer﹕ Enabling debug mode 0

07-16 11:25:39.510 2146-2170/com.flameaters.boombox.boomboxap W/EGL_emulation﹕ eglSurfaceAttrib not implemented

07-16 11:25:39.511 2146-2170/com.flameaters.boombox.boomboxap W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xb4b500e0, error=EGL_SUCCESS

07-16 11:25:39.568 2146-2146/com.flameaters.boombox.boomboxap I/Choreographer﹕ Skipped 34 frames! The application may be doing too much work on its main thread.

07-16 11:25:48.058 2146-2146/com.flameaters.boombox.boomboxap I/Choreographer﹕ Skipped 31 frames! The application may be doing too much work on its main thread.

07-16 11:25:48.335 2146-2170/com.flameaters.boombox.boomboxap W/EGL_emulation﹕ eglSurfaceAttrib not implemented

07-16 11:25:48.335 2146-2170/com.flameaters.boombox.boomboxap W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa5ca73e0, error=EGL_SUCCESS

07-16 11:25:48.413 2146-2170/com.flameaters.boombox.boomboxap W/EGL_emulation﹕ eglSurfaceAttrib not implemented

07-16 11:25:48.413 2146-2170/com.flameaters.boombox.boomboxap W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa5ca7420, error=EGL_SUCCESS

07-16 11:25:49.801 2146-2162/com.flameaters.boombox.boomboxap I/art﹕ Background sticky concurrent mark sweep GC freed 386(19KB) AllocSpace objects, 0(0B) LOS objects, 10% free, 1235KB/1378KB, paused 13.092ms total 139.099ms

07-16 11:25:49.812 2146-2162/com.flameaters.boombox.boomboxap W/art﹕ Suspending all threads took: 9.515ms

07-16 11:25:50.007 2146-2162/com.flameaters.boombox.boomboxap I/art﹕ Background partial concurrent mark sweep GC freed 824(40KB) AllocSpace objects, 0(0B) LOS objects, 29% free, 1223KB/1735KB, paused 1.929ms total 112.541ms

07-16 11:25:55.610 2146-2155/com.flameaters.boombox.boomboxap W/art﹕ Suspending all threads took: 19.089ms

07-16 11:25:55.897 2146-2162/com.flameaters.boombox.boomboxap I/art﹕ Background sticky concurrent mark sweep GC freed 2846(198KB) AllocSpace objects, 5(150KB) LOS objects, 8% free, 1590KB/1735KB, paused 1.486ms total 189.098ms

07-16 11:25:56.099 2146-2155/com.flameaters.boombox.boomboxap W/art﹕ Suspending all threads took: 7.638ms

--------- beginning of crash

07-16 11:25:56.499 2146-2280/com.flameaters.boombox.boomboxap E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-136

Process: com.flameaters.boombox.boomboxap, PID: 2146

java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/naming/directory/InitialDirContext;

at org.jivesoftware.smack.util.dns.javax.JavaxResolver.(JavaxResolver.java :50)

at java.lang.Class.classForName(Native Method)

at java.lang.Class.forName(Class.java:309)

at org.jivesoftware.smack.SmackInitialization.loadSmackClass(SmackInitialization.j ava:213)

at org.jivesoftware.smack.SmackInitialization.parseClassesToLoad(SmackInitializati on.java:193)

at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitializatio n.java:163)

at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitializatio n.java:148)

at org.jivesoftware.smack.SmackInitialization.(SmackInitialization.java:11 6)

at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96 )

at org.jivesoftware.smack.ConnectionConfiguration.(ConnectionConfiguration .java:38)

at com.flameaters.boombox.boomboxap.MainActivity$DoThread.run(MainActivity.java:14 2)

at java.lang.Thread.run(Thread.java:818)

Caused by: java.lang.ClassNotFoundException: Didn’t find class “javax.naming.directory.InitialDirContext” on path: DexPathList[[zip file “/data/app/com.flameaters.boombox.boomboxap-1/base.apk”],nativeLibraryDirectori es=[/vendor/lib, /system/lib]]

at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)

at java.lang.ClassLoader.loadClass(ClassLoader.java:511)

at java.lang.ClassLoader.loadClass(ClassLoader.java:469)

at org.jivesoftware.smack.util.dns.javax.JavaxResolver.(JavaxResolver.java :50)

at java.lang.Class.classForName(Native Method)

at java.lang.Class.forName(Class.java:309)

at org.jivesoftware.smack.SmackInitialization.loadSmackClass(SmackInitialization.j ava:213)

at org.jivesoftware.smack.SmackInitialization.parseClassesToLoad(SmackInitializati on.java:193)

at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitializatio n.java:163)

at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitializatio n.java:148)

at org.jivesoftware.smack.SmackInitialization.(SmackInitialization.java:11 6)

at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96 )

at org.jivesoftware.smack.ConnectionConfiguration.(ConnectionConfiguration .java:38)

at com.flameaters.boombox.boomboxap.MainActivity$DoThread.run(MainActivity.java:14 2)

at java.lang.Thread.run(Thread.java:818)

Suppressed: java.lang.ClassNotFoundException: javax.naming.directory.InitialDirContext

at java.lang.Class.classForName(Native Method)

at java.lang.BootClassLoader.findClass(ClassLoader.java:781)

at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)

at java.lang.ClassLoader.loadClass(ClassLoader.java:504)

… 13 more

Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

07-16 11:25:56.616 2146-2155/com.flameaters.boombox.boomboxap W/art﹕ Suspending all threads took: 8.089ms

07-16 11:25:56.630 2146-2162/com.flameaters.boombox.boomboxap I/art﹕ Background partial concurrent mark sweep GC freed 1138(117KB) AllocSpace objects, 3(81KB) LOS objects, 24% free, 1941KB/2MB, paused 39.703ms total 131.085ms

07-16 11:26:03.821 2146-2159/com.flameaters.boombox.boomboxap W/art﹕ Suspending all threads took: 9.723ms

Did you read and follow the instructions of the Smack 4.1 Readme?

Yes, I believe I have complied with it the following ways as shown in the codes above

  1. XMPPConnection is now an abstract class, I am using mConnection = new XMPPTCPConnection(config.build()); to intantiate XMPPConnection. It crashes upon intantiating the XMPPTCPConnection class.
  2. ConnectionConfiguration uses the Builder pattern. My code uses XMPPTCPConnectionConfiguration.Builder connconfig = XMPPTCPConnectionConfiguration.builder() to set the connection parameters

Additionally, some other posts suggest to avoid creating the connection in the main thread which can crash upon a slow/ heavy connection, so my code creates the connection in a separate thread as follows (refer further below). The new thread runs fine if I comment out the instantiation of either or both of XMPTCPConnection and/or XMPTCPConnectionConfiguration. When I do instantiate any of these two objects as mentioned in points 1 and 2 above, the application crashes.

As the error trace shows, the error is due to java.lang.NoClassDefFoundError

Failed resolution of: Ljavax/naming/directory/InitialDirContext;

at org.jivesoftware.smack.util.dns.javax.JavaxResolver.(JavaxResolver.java :50)

So this is in the Smack library itself, not in my code. I am puzzled as to why others are not affected by the same problem as I am facing. I am using the Smack 4.1.3 library (jar files) downloaded from IgniteRealtime.org. Alternatively, I set references of dependencies for using Smack 4.2.0 Alpha directly from the online repository and the same crash still happens. The Build dependencies are shown further below this reply.

Independent thread for connecting to XMPP server as follows

class DoThread implements Runnable {

String strServer = “”;

String strUserId = “”;

String strPassword = “”;

public String retStr = “”;

DoThread(String pServer, String pUserid, String pPassword) {

this.strServer = pServer;

this.strUserId=pUserid;

this.strPassword=pPassword;

}

public void run() {

//Context context = getApplicationContext();
//SmackAndroid.init(context);

String retStr = “”;

XMPPTCPConnectionConfiguration.Builder connconfig = XMPPTCPConnectionConfiguration.builder(); //Crash here, because the rest of codes are commented out below - if line this is commented out no crash takes place
//connconfig.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
//connconfig.setUsernameAndPassword(strUserId+ “@” + strServer, strPassword);
//connconfig.setServiceName(strServer);
//connconfig.setHost(strServer);
//connconfig.setPort(5222);
//connconfig.setDebuggerEnabled(true);
//connconfig.setSocketFactory(SSLSocketFactory.getDefault());

/*
mConnection = new XMPPTCPConnection(config.build());
try {
mConnection.connect();
} catch (SmackException | IOException | XMPPException e) {
e.printStackTrace();
}
*/

// ConnectionConfiguration connconfig = new ConnectionConfiguration(strServer); //Crash here, because the rest of codes are commented out below - if line this is commented out no crash takes place
// connconfig.setDebuggerEnabled(true);
// XMPPConnection connection = new XMPPConnection(connconfig);

/*
try {
connection.connect();
} catch (XMPPException e) {
retStr = e.getMessage();
}

// Most servers require you to login before performing other tasks.
try {
connection.login(strUserId, strPassword);
}
catch (XMPPException e) {
retStr = e.getMessage();
}

Build file copy as follows

apply plugin: ‘com.android.application’

android {

compileSdkVersion 22
buildToolsVersion '22.0.1’
defaultConfig {

applicationId "com.flameaters.boombox.boomboxap"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName “1.0”
}

buildTypes {

release {

minifyEnabled false
proguardFiles getDefaultProguardFile(‘proguard-android.txt’), ‘proguard-rules.pro
}

}

productFlavors {

}

}

dependencies {

compile fileTree(include: [’*.jar’], dir: ‘libs’)

compile files(‘libs/smack-android-4.1.3.jar’)

compile files(‘libs/smack-core-4.1.3.jar’)

compile files(‘libs/smack-im-4.1.3.jar’)

compile files(‘libs/smack-sasl-provided-4.1.3.jar’)

compile files(‘libs/smack-tcp-4.1.3.jar’)

compile 'org.jxmpp:jxmpp-util-cache:0.5.0-alpha6’
compile 'com.android.support:appcompat-v7:22.2.0’
compile ‘org.jxmpp:jxmpp-core:0.5.0-alpha6’
}

Thanks for helping out.

I have tried other dependencies, going backward in versions to match the ones exactly on XMPP 4.1 readme, as follows as the app still crashes with the same errors

New dependencies matching the ones in 4.1 readme exactly

dependencies {

compile fileTree(include: [’*.jar’], dir: ‘libs’)

compile files(‘libs/smack-android-4.1.3.jar’)

compile files(‘libs/smack-core-4.1.3.jar’)

compile files(‘libs/smack-tcp-4.1.3.jar’)

compile files(‘libs/smack-extensions-4.1.3.jar’)

compile files(‘libs/smack-experimental-4.1.3.jar’)

compile files(‘libs/smack-resolver-minidns-4.1.3.jar’)

compile files(‘libs/smack-sasl-provided-4.1.3.jar’)

compile files(‘libs/smack-im-4.1.3.jar’)

compile(‘org.jxmpp:jxmpp-core:0.4.2-beta1’)

compile(‘org.jxmpp:jxmpp-util-cache:0.4.2-beta1’)

compile(‘de.measite.minidns:minidns:0.1.1’)

compile ‘com.android.support:appcompat-v7:22.2.0’
}

Error trace producing the same error as before

Process: com.flameaters.boombox.boomboxap, PID: 3721

java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/naming/directory/InitialDirContext;

at org.jivesoftware.smack.util.dns.javax.JavaxResolver.(JavaxResolver.java :50)

at java.lang.Class.classForName(Native Method)

at java.lang.Class.forName(Class.java:309)

at org.jivesoftware.smack.SmackInitialization.loadSmackClass(SmackInitialization.j ava:213)

at org.jivesoftware.smack.SmackInitialization.parseClassesToLoad(SmackInitializati on.java:193)

at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitializatio n.java:163)

at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitializatio n.java:148)

at org.jivesoftware.smack.SmackInitialization.(SmackInitialization.java:11 6)

at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96 )

at org.jivesoftware.smack.ConnectionConfiguration.(ConnectionConfiguration .java:38)

at com.flameaters.boombox.boomboxap.MainActivity$DoThread.run(MainActivity.java:14 2)

at java.lang.Thread.run(Thread.java:818)

Caused by: java.lang.ClassNotFoundException: Didn’t find class “javax.naming.directory.InitialDirContext”

Thanks.

It appears you pull smack-resolver-javax somehow in your class path. There is no reason to add Smack as jar files to a gradle build project, simply define the dependencies as shown in the Readme.

Moving the dependencies further backwards from Smack 4.1.3 to Smack 4.1.1 gives the following error on Gradle build

AGPBI: {“kind”:“SIMPLE”,“text”:“com.android.dex.DexException: Multiple dex files define Lorg/jivesoftware/smack/android/AndroidSmackInitializer;”,“position”:{},“origin al”:“com.android.dex.DexException: Multiple dex files define Lorg/jivesoftware/smack/android/AndroidSmackInitializer;”}

The dependencies follow the ones in Smack 4.1 Readme files exactly (https://github.com/igniterealtime/Smack/wiki/Smack-4.1-Readme-and-Upgrade-Guide - using Eclipse section) as follows

dependencies {

compile fileTree(include: [’*.jar’], dir: ‘libs’)

compile(‘org.igniterealtime.smack:smack-android:4.1.1’)

compile(‘org.igniterealtime.smack:smack-android-extensions:4.1.1’)

compile(‘org.igniterealtime.smack:smack-core:4.1.1’)

compile(‘org.igniterealtime.smack:smack-tcp:4.1.1’)

compile(‘org.igniterealtime.smack:smack-extensions:4.1.1’)

compile(‘org.igniterealtime.smack:smack-experimental:4.1.1’)

compile(‘org.igniterealtime.smack:smack-resolver-minidns:4.1.1’)

compile(‘org.igniterealtime.smack:smack-sasl-provided:4.1.1’)

compile(‘org.igniterealtime.smack:smack-im:4.1.1’)

compile(‘org.jxmpp:jxmpp-core:0.4.2-beta1’)

compile(‘org.jxmpp:jxmpp-util-cache:0.4.2-beta1’)

compile(‘de.measite.minidns:minidns:0.1.1’)

compile ‘com.android.support:appcompat-v7:22.2.0’
}

}

This produces a compilation error revolving around

AGPBI: {“kind”:“SIMPLE”,“text”:“com.android.dex.DexException: Multiple dex files define Lorg/jivesoftware/smack/android/AndroidSmackInitializer;”,“position”:{},“origin al”:“com.android.dex.DexException: Multiple dex files define Lorg/jivesoftware/smack/android/AndroidSmackInitializer;”}

Error details from the Gradle build message and Gradle console are as listed below –

Gradle build messages

Information:Gradle tasks [:app:assembleDebug]

Warning:Dependency xpp3:xpp3:1.1.4c is ignored for debug as it may be conflicting with the internal version provided by Android.

In case of problem, please repackage it with jarjar to change the class packages

Warning:Dependency xpp3:xpp3:1.1.4c is ignored for release as it may be conflicting with the internal version provided by Android.

In case of problem, please repackage it with jarjar to change the class packages

:app:preBuild UP-TO-DATE

:app:preDebugBuild UP-TO-DATE

:app:checkDebugManifest

:app:preReleaseBuild UP-TO-DATE

:app:prepareComAndroidSupportAppcompatV72220Library UP-TO-DATE

:app:prepareComAndroidSupportSupportV42220Library UP-TO-DATE

:app:prepareDebugDependencies

:app:compileDebugAidl UP-TO-DATE

:app:compileDebugRenderscript UP-TO-DATE

:app:generateDebugBuildConfig UP-TO-DATE

:app:generateDebugAssets UP-TO-DATE

:app:mergeDebugAssets UP-TO-DATE

:app:generateDebugResValues UP-TO-DATE

:app:generateDebugResources UP-TO-DATE

:app:mergeDebugResources UP-TO-DATE

:app:processDebugManifest UP-TO-DATE

:app:processDebugResources UP-TO-DATE

:app:generateDebugSources UP-TO-DATE

:app:processDebugJavaRes UP-TO-DATE

:app:compileDebugJava UP-TO-DATE

:app:compileDebugNdk UP-TO-DATE

:app:compileDebugSources UP-TO-DATE

:app:preDexDebug UP-TO-DATE

:app:dexDebug

UNEXPECTED TOP-LEVEL EXCEPTION:

com.android.dex.DexException: Multiple dex files define Lorg/jivesoftware/smack/android/AndroidSmackInitializer;

at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)

at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)

at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)

at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)

at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)

at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)

at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)

at com.android.dx.command.dexer.Main.run(Main.java:246)

at com.android.dx.command.dexer.Main.main(Main.java:215)

at com.android.dx.command.Main.main(Main.java:106)

Error:Execution failed for task ‘:app:dexDebug’.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘D:\Java\JDK\bin\java.exe’’ finished with non-zero exit value 2

Information:BUILD FAILED

Information:Total time: 2.044 secs

Information:1 error

Information:2 warnings

Information:See complete output in console

Gradle output console

Executing tasks: [:app:assembleDebug]

Configuration on demand is an incubating feature.

WARNING: Dependency xpp3:xpp3:1.1.4c is ignored for debug as it may be conflicting with the internal version provided by Android.

In case of problem, please repackage it with jarjar to change the class packages

WARNING: Dependency xpp3:xpp3:1.1.4c is ignored for release as it may be conflicting with the internal version provided by Android.

In case of problem, please repackage it with jarjar to change the class packages

:app:preBuild UP-TO-DATE

:app:preDebugBuild UP-TO-DATE

:app:checkDebugManifest

:app:preReleaseBuild UP-TO-DATE

:app:prepareComAndroidSupportAppcompatV72220Library UP-TO-DATE

:app:prepareComAndroidSupportSupportV42220Library UP-TO-DATE

:app:prepareDebugDependencies

:app:compileDebugAidl UP-TO-DATE

:app:compileDebugRenderscript UP-TO-DATE

:app:generateDebugBuildConfig UP-TO-DATE

:app:generateDebugAssets UP-TO-DATE

:app:mergeDebugAssets UP-TO-DATE

:app:generateDebugResValues UP-TO-DATE

:app:generateDebugResources UP-TO-DATE

:app:mergeDebugResources UP-TO-DATE

:app:processDebugManifest UP-TO-DATE

:app:processDebugResources UP-TO-DATE

:app:generateDebugSources UP-TO-DATE

:app:processDebugJavaRes UP-TO-DATE

:app:compileDebugJava UP-TO-DATE

:app:compileDebugNdk UP-TO-DATE

:app:compileDebugSources UP-TO-DATE

:app:preDexDebug UP-TO-DATE

:app:dexDebug

AGPBI: {“kind”:“SIMPLE”,“text”:“UNEXPECTED TOP-LEVEL EXCEPTION:”,“position”:{},“original”:“UNEXPECTED TOP-LEVEL EXCEPTION:”}

AGPBI: {“kind”:“SIMPLE”,“text”:“com.android.dex.DexException: Multiple dex files define Lorg/jivesoftware/smack/android/AndroidSmackInitializer;”,“position”:{},“origin al”:“com.android.dex.DexException: Multiple dex files define Lorg/jivesoftware/smack/android/AndroidSmackInitializer;”}

AGPBI: {“kind”:“SIMPLE”,“text”:"\tat com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)",“position “:{},“original”:”\tat com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)”}

AGPBI: {“kind”:“SIMPLE”,“text”:"\tat com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)",“position”:{ },“original”:"\tat com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)"}

AGPBI: {“kind”:“SIMPLE”,“text”:"\tat com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)",“position”:{ },“original”:"\tat com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)"}

AGPBI: {“kind”:“SIMPLE”,“text”:"\tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)",“position”:{},“o riginal”:"\tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)"}

AGPBI: {“kind”:“SIMPLE”,“text”:"\tat com.android.dx.merge.DexMerger.merge(DexMerger.java:189)",“position”:{},“origin al”:"\tat com.android.dx.merge.DexMerger.merge(DexMerger.java:189)"}

AGPBI: {“kind”:“SIMPLE”,“text”:"\tat com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)",“posit ion”:{},“original”:"\tat com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)"}

AGPBI: {“kind”:“SIMPLE”,“text”:"\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)",“position”:{},“ori ginal”:"\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)"}

AGPBI: {“kind”:“SIMPLE”,“text”:"\tat com.android.dx.command.dexer.Main.run(Main.java:246)",“position”:{},“original”: “\tat com.android.dx.command.dexer.Main.run(Main.java:246)”}

AGPBI: {“kind”:“SIMPLE”,“text”:"\tat com.android.dx.command.dexer.Main.main(Main.java:215)",“position”:{},“original” :"\tat com.android.dx.command.dexer.Main.main(Main.java:215)"}

AGPBI: {“kind”:“SIMPLE”,“text”:"\tat com.android.dx.command.Main.main(Main.java:106)",“position”:{},“original”:"\tat com.android.dx.command.Main.main(Main.java:106)"}

FAILED

FAILURE: Build failed with an exception.

  • What went wrong:

Execution failed for task ‘:app:dexDebug’.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘D:\Java\JDK\bin\java.exe’’ finished with non-zero exit value 2

  • Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 2.044 secs

How do I resolve the duplication error - do I need to remove any of the dependencies suggested by Smack 4.1 Readme file - which dependency should be removed?

Thanks

Thanks Flow, I have removed all Smack jar files from my dependencies and now the dependencies are as shown in my reply below this. I am now getting a duplicate declaration error for AndroidSmackIntializer as shown in the reply below.

Hi again Flow, I have managed to recompile the project successfully by

  1. Changing the dependencies from Smack 4.1.3 to Smack 4.1.1, and
  2. Deleting all Smack jar files from the libs directory as you pointed out

At this moment it appears that using Smack 4.1.1 does not produce the crashes as before. I am still trying things and hopefully everything works at which point I can wrap up this case and summarise what works.

Thank you again.

I would like to thank Flow for helping to troubleshoot this problem. His proddings into the right direction has been instrumental in resolving this problem. To recap, initially Smack would crash upon initialization of objects defined in the Smack API. The solution was resolved by the following

  1. Downgrading from Smack 4.2.0 to Smack 4.3.1
  2. Using the dependencies as shown below (and clearing the lib directory too!)

dependencies {

compile fileTree(include: [’*.jar’], dir: ‘libs’)

compile 'org.igniterealtime.smack:smack-android:4.1.1’
compile 'org.igniterealtime.smack:smack-android-extensions:4.1.1’
compile 'org.igniterealtime.smack:smack-core:4.1.1’
compile 'org.igniterealtime.smack:smack-tcp:4.1.1’
compile 'org.igniterealtime.smack:smack-extensions:4.1.1’
compile 'org.igniterealtime.smack:smack-experimental:4.1.1’
compile 'org.igniterealtime.smack:smack-resolver-minidns:4.1.1’
compile 'org.igniterealtime.smack:smack-sasl-provided:4.1.1’
compile 'org.igniterealtime.smack:smack-im:4.1.1’
compile 'org.jxmpp:jxmpp-core:0.4.2-beta1’
compile 'org.jxmpp:jxmpp-util-cache:0.4.2-beta1’
compile 'de.measite.minidns:minidns:0.1.1’
compile ‘com.android.support:appcompat-v7:22.2.0’
}

I am having a different sort of problem, but the problem of crashes when Smack objects are initialized are solved for now.

The new problem is that I am getting a Socket Fail, EACCES (permission denied) error - but that’s another story. For those who wish to refer to my source code, here it is, creating a connection on a separate thread using a Callable object (instead of Runnable) and returning a confirmation (or error message) upon successful (or failed connection).

package com.flameaters.boombox.boomboxap;

import android.content.Context;

import android.support.v7.app.AppCompatActivity ;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

import android.view.inputmethod.InputMethodManager;

import android.widget.ArrayAdapter;

import android.widget.Button;

import android.widget.EditText;

import android.widget.ListView;

import android.widget.TextView;

import java.util.ArrayList;

import java.util.*;

import java.util.concurrent.*;

//import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.ConnectionConfiguration;

import org.jivesoftware.smack.XMPPConnection;

import org.jivesoftware.smack.XMPPException;

import org.jivesoftware.smack.tcp.XMPPTCPConnection;

import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;

import javax.net.ssl.SSLSocketFactory;

public class MainActivity extends AppCompatActivity {

final int XMPP_CONNECT = 1;

final int XMPP_DISCONNECT = 0;

private TextView label1;

private EditText textServer;

private EditText textUserId;

private EditText textPassword;

private ListView listView1;

private Button button1;

private ArrayList itemList;

private ArrayAdapter listAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

label1 = (TextView) findViewById(R.id.label1);

textServer = (EditText) findViewById(R.id.textServer);

textUserId = (EditText) findViewById(R.id.textUserId);

textPassword = (EditText) findViewById(R.id.textPassword);

listView1 = (ListView) findViewById(R.id.listView1);

button1 = (Button) findViewById(R.id.button1);

itemList = new ArrayList();

listAdapter = new ArrayAdapter(this, R.layout.simplerow, itemList);

listView1.setAdapter(listAdapter);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);

return true;

}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {

return true;

}

return super.onOptionsItemSelected(item);

}

public void button1_click(View view) {

// Do something in response to button click

String responseStr = “”;

String labelStr = “”;

clearList();

responseStr = “You clicked RUN”;

listResponse(responseStr, responseStr);

responseStr = "Connecting to server at " + textServer.getText().toString();

listResponse(responseStr, responseStr);

labelStr = responseStr;

responseStr = createConnection();

listResponse(labelStr,responseStr);

responseStr = “Run ended”;

listResponse(responseStr,responseStr);

}

private void listResponse(String labelText, String listText) {

label1.setText(labelText);

listAdapter.add(listText);

listAdapter.notifyDataSetChanged();

hideKeyboard();

}

private void clearList() {

listAdapter.clear();

listAdapter.notifyDataSetChanged();

}

private void hideKeyboard() {

// Check if no view has focus:
View view = this.getCurrentFocus();

if (view != null) {

InputMethodManager inputManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);

inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

}

}

private String createConnection() {

String strServer = this.textServer.getText().toString();

String strUserId = this.textUserId.getText().toString();

String strPassword = this.textPassword.getText().toString();

String retStr = “”;

ExecutorService executer = Executors.newFixedThreadPool(1);

Callable doThread = new DoThread(strServer,strUserId,strPassword);

Future future = executer.submit(doThread);

try {

retStr = future.get();

}

catch (ExecutionException | InterruptedException e) {

retStr = e.getMessage();

}

return retStr;

}

}

class DoThread implements Callable {

final int XMPP_DEFAULT_PORT = 5222;

String strServer = “”;

String strUserId = “”;

String strPassword = “”;

String retStr = “”;

DoThread(String pServer, String pUserid, String pPassword) {

this.strServer = pServer;

this.strUserId=pUserid;

this.strPassword=pPassword;

}

public String call() {

//Context context = getApplicationContext();
//SmackAndroid.init(context);

XMPPTCPConnectionConfiguration.Builder connconfig = XMPPTCPConnectionConfiguration.builder(); //Crash here, because the rest of codes are commented out below
connconfig.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);

connconfig.setUsernameAndPassword(strUserId + “@” + strServer, strPassword);

connconfig.setServiceName(strServer);

connconfig.setHost(strServer);

connconfig.setPort(XMPP_DEFAULT_PORT);

connconfig.setDebuggerEnabled(true);

connconfig.setSocketFactory(SSLSocketFactory.getDefault());

XMPPTCPConnection connection = new XMPPTCPConnection(connconfig.build());

try {

connection.connect();

connection.login();

retStr = “Connection succeeded”;

} catch (org.jivesoftware.smack.SmackException | XMPPException | java.io.IOException e) {

e.printStackTrace();

retStr = e.getMessage();

}

return retStr;

}

}

You can and should remove all dependencies besides

  • smack-tcp
  • smack-android-extensions
  • smack-experimental

Every other dependency is either a direct or transitive dependencies of those.

Exactly the same problem and looking for solution!