Smack throws "NoClassDefFoundError: Failed resolution of: Lorg/jxmpp/util/XmppStringUtils"
Asked Answered
H

3

6

I got a problem with my app in which I want to create a simple XMPP client that connects to my server. I got the following problem when I'm starting the app (compilation runs through without problems), but my app closes instantly.

   java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jxmpp/util/XmppStringUtils;
        at org.jivesoftware.smack.provider.ProviderManager.getKey(ProviderManager.java:314)
        at org.jivesoftware.smack.provider.ProviderManager.addStreamFeatureProvider(ProviderManager.java:304)
        at org.jivesoftware.smack.provider.ProviderManager.addLoader(ProviderManager.java:140)
        at org.jivesoftware.smack.initializer.UrlInitializer.initialize(UrlInitializer.java:54)
        at org.jivesoftware.smack.SmackInitialization.loadSmackClass(SmackInitialization.java:232)
        at org.jivesoftware.smack.SmackInitialization.parseClassesToLoad(SmackInitialization.java:193)
        at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:163)
        at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:148)
        at org.jivesoftware.smack.SmackInitialization.<clinit>(SmackInitialization.java:116)
        at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96)
        at org.jivesoftware.smack.ConnectionConfiguration.<clinit>(ConnectionConfiguration.java:38)
        at org.reisacher.zapp.Main.login(Main.java:30)
        at org.reisacher.zapp.Main.onCreate(Main.java:73)
        at android.app.Activity.performCreate(Activity.java:5990)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
        at android.app.ActivityThread.access$800(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5257)
        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:903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "org.jxmpp.util.XmppStringUtils" on path: DexPathList[[zip file "/data/app/org.reisacher.zapp-1/base.apk"],nativeLibraryDirectories=[/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.provider.ProviderManager.getKey(ProviderManager.java:314)
at org.jivesoftware.smack.provider.ProviderManager.addStreamFeatureProvider(ProviderManager.java:304)
            at org.jivesoftware.smack.provider.ProviderManager.addLoader(ProviderManager.java:140)
            at org.jivesoftware.smack.initializer.UrlInitializer.initialize(UrlInitializer.java:54)
            at org.jivesoftware.smack.SmackInitialization.loadSmackClass(SmackInitialization.java:232)
            at org.jivesoftware.smack.SmackInitialization.parseClassesToLoad(SmackInitialization.java:193)
            at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:163)
            at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:148)
            at org.jivesoftware.smack.SmackInitialization.<clinit>(SmackInitialization.java:116)
            at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96)
            at org.jivesoftware.smack.ConnectionConfiguration.<clinit>(ConnectionConfiguration.java:38)
            at org.reisacher.zapp.Main.login(Main.java:30)
            at org.reisacher.zapp.Main.onCreate(Main.java:73)
            at android.app.Activity.performCreate(Activity.java:5990)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            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:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Suppressed: java.lang.ClassNotFoundException: org.jxmpp.util.XmppStringUtils
        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)
        ... 27 more
 Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

But I somehow can't find anything related to the missing "XmppStringUtils"

This is the code in line 30

public void login() throws XMPPException, IOException, SmackException {
    XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
            .setServiceName("reisacher.de")
            .setHost("192.168.178.6")
            .setPort(5222)
            .build();

    AbstractXMPPConnection connection = new XMPPTCPConnection(config);
    connection.connect();
    connection.login(username, password);
}

And these are my imports

import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;

Plus my build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply plugin: 'jetty'
buildscript {
    repositories {
        maven {
            url 'https://oss.sonatype.org/content/repositories/snapshots'
        }
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
    }
}

dependencies {
    compile "org.igniterealtime.smack:smack-android:4.1.1"
    compile "org.igniterealtime.smack:smack-tcp:4.1.1"
    // optional features
    compile "org.igniterealtime.smack:smack-android-extensions:4.1.1"
    compile "org.igniterealtime.smack:smack-core:4.1.1"
}

allprojects {
    repositories {
        jcenter()
    }
}

Thanks

Hindoo answered 31/5, 2015 at 21:39 Comment(2)
you solve this error?Bouquet
Yes, I forgot to add the dependencies in the 2nd build.gradle file. Check if you got all your dependencies in $root/build.gradle and $root/app/build.gradle. That solved the error for meHindoo
I
2

From NoClassDefFoundError's javadoc:

Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.

Java uses dynamic linking, which means that the symbols (class names, ...) are linked when first used. As Mohit already pointed out, it appears you are missing the JXMPP library, which is a (transitive) dependency of Smack. I assume you did add Smack to your project by simply putting it into the libs/ folder. This approach is not recommended, as you easily miss a trasitive dependency of Smack, like it happened to you. Instead use a build system which is able to resolve those dependencies like Maven or Gradle. See also:

Interval answered 1/6, 2015 at 8:35 Comment(2)
Thanks, forgot to add the "compile ..." lines in the 2nd .gradle file. Works like a charm now, without manual library workHindoo
@Interval , it seems that even gradle does not resolve these transitive dependencies that you removed. Check out https://github.com/deniswisedeniswise/smacktutorial, it builds but produces the same runtime errorSpermatogonium
E
8

You required four extra jar files.

1) jxmpp-core.jar

2) jxmpp-jid.jar

3) jxmpp-stringprep-libidn

4) jxmpp-util-cache

You can download all of them from below link.

https://oss.sonatype.org/content/repositories/releases/org/jxmpp/

Egoism answered 1/6, 2015 at 7:40 Comment(1)
thanks for actually sending me to the libs rather than just saying "use maven"Consecution
P
3

The issue comes from one dependency de.measite.minidns that pushed a update with a bug. So I fixed it like that by excluding to auto-dependency and including the last stable release. It fixed my problem.

compile('org.igniterealtime.smack:smack-android-extensions:4.2.0') {
    exclude group: 'de.measite.minidns'
}
compile('org.igniterealtime.smack:smack-tcp:4.2.0') {
    exclude group: 'de.measite.minidns'
}
compile group: 'de.measite.minidns', name: 'minidns-hla', version: '0.2.2'
Pendent answered 15/9, 2017 at 12:13 Comment(0)
I
2

From NoClassDefFoundError's javadoc:

Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.

Java uses dynamic linking, which means that the symbols (class names, ...) are linked when first used. As Mohit already pointed out, it appears you are missing the JXMPP library, which is a (transitive) dependency of Smack. I assume you did add Smack to your project by simply putting it into the libs/ folder. This approach is not recommended, as you easily miss a trasitive dependency of Smack, like it happened to you. Instead use a build system which is able to resolve those dependencies like Maven or Gradle. See also:

Interval answered 1/6, 2015 at 8:35 Comment(2)
Thanks, forgot to add the "compile ..." lines in the 2nd .gradle file. Works like a charm now, without manual library workHindoo
@Interval , it seems that even gradle does not resolve these transitive dependencies that you removed. Check out https://github.com/deniswisedeniswise/smacktutorial, it builds but produces the same runtime errorSpermatogonium

© 2022 - 2024 — McMap. All rights reserved.