Wednesday, 7 September 2016

java - Connecting to XMPP server from android



The same code is working if I run the class from eclipse as a java application but when I am using same class in android studio I am getting the following RuntimeException.



java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/security/sasl/Sasl; 


The log :




FATAL EXCEPTION: Thread-62267
Process: com.abcd.abcd, PID: 14825
java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/security/sasl/Sasl;
at org.jivesoftware.smack.sasl.SASLMechanism.authenticate(SASLMechanism.java:92)
at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:319)
at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:203)
at com.abcd.abcd.XmppManager.login(XmppManager.java:99)
at com.abcd.abcd.Main.initializeXmppConnection(Main.java:78)
at com.abcd.abcd.Main.init(Main.java:72)
at com.abcd.abcd.Main.(Main.java:61)

at com.abcd.abcd.MainActivity$1.run(MainActivity.java:32)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.security.sasl.Sasl" on path: DexPathList[[zip file "/data/app/com.abcd.abcd-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.sasl.SASLMechanism.authenticate(SASLMechanism.java:92) 
at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:319) 
at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:203) 
at com.abcd.abcd.XmppManager.login(XmppManager.java:99) 

at com.abcd.abcd.Main.initializeXmppConnection(Main.java:78) 
at com.abcd.abcd.Main.init(Main.java:72) 
at com.abcd.abcd.Main.(Main.java:61) 
at com.abcd.abcd.MainActivity$1.run(MainActivity.java:32) 
at java.lang.Thread.run(Thread.java:818) 
Suppressed: java.lang.ClassNotFoundException: javax.security.sasl.Sasl
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)

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


I am stuck here and really not getting what the problem is. Any help guys?


Answer



hi if you want to update your library for studio that is one option is good but if you want to use same code in studio as well then you can visit this code here and check if you are doing correct or not.Some problem with ssl permission check here correct way



private XMPPConnection connect() throws XMPPException, SmackException,
IOException {

if ((this.connection != null) && (this.connection.isConnected())) {
return this.connection;
}

ConnectionConfiguration config = new ConnectionConfiguration(HOST1,
5222);
SmackConfiguration.DEBUG_ENABLED = true;
SASLAuthentication.supportSASLMechanism("MD5", 0);
System.setProperty("smack.debugEnabled", "true");
config.setCompressionEnabled(false);

config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
config.setReconnectionAllowed(true);
config.setSendPresence(true);
config.setRosterLoadedAtLogin(true);

if (Build.VERSION.SDK_INT >= 14) {
config.setKeystoreType("AndroidCAStore");
config.setKeystorePath(null);
} else {
config.setKeystoreType("BKS");

String str = System.getProperty("javax.net.ssl.trustStore");
if (str == null) {
str = System.getProperty("java.home") + File.separator + "etc"
+ File.separator + "security" + File.separator
+ "cacerts.bks";
}
config.setKeystorePath(str);
}
if (connection == null) {
this.connection = new XMPPTCPConnection(config);

}
this.connection.connect();
Roster roster = connection.getRoster();
roster.addRosterListener(new RosterListener() {

@Override
public void presenceChanged(Presence arg0) {
Log.d("deb", "ug");
}


@Override
public void entriesUpdated(Collection arg0) {
Log.d("deb", "ug");
}

@Override
public void entriesDeleted(Collection arg0) {
Log.d("deb", "ug");
}


@Override
public void entriesAdded(Collection arg0) {
Log.d("deb", "ug");
}
});
return this.connection;
}


Thankyou




Hope this will help you.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...