powered by Jive Software

ClassNotFoundException in an android app

I am getting a ClassNotFoundException in an android app.

here is the result:

Process: com.nedtech.kipapp, PID: 21373

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:317)

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.nedtech.kipapp.LoginActivity$1.onClick(LoginActivity.java:47)

at android.view.View.performClick(View.java:4909)

at android.view.View$PerformClick.run(View.java:20390)

at android.os.Handler.handleCallback(Handler.java:815)

at android.os.Handler.dispatchMessage(Handler.java:104)

at android.os.Looper.loop(Looper.java:194)

at android.app.ActivityThread.main(ActivityThread.java:5796)

at java.lang.reflect.Method.invoke(Native Method)

at java.lang.reflect.Method.invoke(Method.java:372)

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1010 )

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)

Caused by: java.lang.ClassNotFoundException: Didn’t find class “javax.naming.directory.InitialDirContext” on path: DexPathList[[dex file “/data/data/com.nedtech.kipapp/files/instant-run/dex/slice-xpp3_xpath-1.1.4c_60 746da3324092e98fd5c19ba0f2785b1e29ab8e-classes.dex”, dex file “/data/data/com.nedtech.kipapp/files/instant-run/dex/slice-support-annotations- 23.2.1_1c878c64e3f8fc576393fb136e8c732b9b1e75a1-classes.dex”, dex file “/data/data/com.nedtech.kipapp/files/instant-run/dex/slice-smack-tcp-4.1.7_0a90 65e511ccca14933db4abe839330d38d2f258-classes.dex”, dex file “/data/data/com.nedtech.kipapp/files/instant-run/dex/slice-smack-sasl-provided- 4.1.7_e5ad85c888aac120b42f7131b5431ed0bcbce269-classes.dex”, dex file “/data/data/com.nedtech.kipapp/files/instant-run/dex/slice-smack-sasl-javax-4.1 .7_87d5c84ed8a5014f5a2749048b6585d62e190f01-classes.dex”, dex file “/data/data/com.nedtech.kipapp/files/instant-run/dex/slice-smack-resolver-minid ns-4.1.7_f9466b63ae75c7dc0b3f4c2046654cb77b39b3f8-classes.dex”, dex file “/data/data/com.nedtech.kipapp/files/instant-run/dex/slice-smack-resolver-javax -4.1.7_3d32f51ea53ee061234f8bc0a79ea95739920dff-classes.dex”, dex file “/data/data/com.nedtech.kipapp/files/instant-run/dex/slice-smack-resolver-dnsja va-4.1.7_f74b9de15ac335c66a27dca28ff2114e15f8a9a6-classes.dex”, dex file “/data/data/com.nedtech.kipapp/files/instant-run/dex/slice-smack-legacy-4.1.7_9 2668d6dee709d09a045b1b84278a3695477a727-classes.dex”, dex file “/data/data/com.nedtech.kipapp/files/instant-run/dex/slice-smack-jingle-old-4.1 .7_8046defbbca4c980951fab1a44cefe00264a3126-classes.dex”, dex file “/data/data/com.nedtech.kipapp/files/instant-run/dex/slice-smack-java7-4.1.7_5f 8b86e2c1302ba06bab0d31e164aef28d768afc-classes.dex”, dex file “/data/data/com.nedtech.kipapp/files/instant-run/dex/slice-smack-im-4.1.7_a1945 9c86ed43439687b94300817123fe9546bae-classes.dex”, dex file “/data/data/com.nedtech.kipapp/files/instant-run/dex/slice-smack-extensions-4.1 .7_084f49e8d839d06ea8e5a7c47e810fdbb21d13e4-classes.dex”, dex file “/data/data/com.nedtech.kipapp/files/instant-run/dex/slice-smack-experimental-4 .1.7_8a386f5b5df256779c487d44d1007fa01af453ec-classes.dex”, dex file “/data/data/com.nedtech.kipapp/files/instant-run/dex/slice-smack-core-4.1.7_8ba c073b55a9011d2b8ba396cd4e0cf160683769-classes.dex”, dex file "/data/data/com.nedtech.kipapp/files/instant-run/dex/slice-smack-bosh-4.1.7_035 05bdaf9cb7c8fb9e92541e2635a9935b

06-15 19:46:25.007 21373-21373/com.nedtech.kipapp I/Process: Sending signal. PID: 21373 SIG: 9

I have the same issues, getting this error:

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

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

The error happens from this code:

XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()

.setHost(mServerAddress)

.setPort(mServerPort)

.setServiceName(getServiceNameFromUserXmppAccount(mUserLogin))

.setUsernameAndPassword(mUserLogin, mUserPassword)

.build();

My Environment:

Android Studio 2.2

Java 8

Smack 4.1.0 or Smack 4.1.7 or Smack 4.1.8

My Build.gradle

compileOptions {

sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

dependencies {

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

compile "org.igniterealtime.smack:smack-android-extensions:4.1.7"
compile "org.igniterealtime.smack:smack-android:4.1.7"
compile "org.igniterealtime.smack:smack-tcp:4.1.7"
compile “org.igniterealtime.smack:smack-im:4.1.7”
}

Can anyone help solving this issue?

Many thanks!

You need to have the following in dependency

compile group: ‘org.igniterealtime.smack’, name: ‘smack-android-extensions’, version: '4.1.8’
compile group: ‘org.igniterealtime.smack’, name: ‘smack-tcp’, version: '4.1.8’
compile group: ‘org.igniterealtime.smack’, name: ‘smack-experimental’, version: ‘4.1.8’

However, the trick for me was to uninstall the app and redeploy. I had tried everything else and dint work. Then I uninstalled and re-installed from studio, and the error went away.

Thanks for your reply Rikin.

I ended up using this in my dependency to make it work:

compile "org.igniterealtime.smack:smack-android-extensions:4.2.0-alpha3"
compile “org.igniterealtime.smack:smack-tcp:4.2.0-alpha3”

Note:

Same project but using version 4.1.7 or 4.1.8 does not work for me.