I'm trying to build a chat application with XMPP protocol using Smack library in android studio. by using Smack version 3.1.0 I could easily connect to open fire server and even I sent a message to a user that were logged in by spark. but I could never receive a message from that user because the processMessage of MessageListener ran just once in compile. as I couldn't get the favorite result I searched over the internet and find out that smack from version 4.1 or upper just support in android.
so I tried to build my app with smack 4.1.4 and resolve many errors. but one error didn't resolved and I couldn't find it on the internet. that's it (of course there are too many more errors but I bring the top 4):
11-10 00:16:03.446 15512-15539/xmppconnectiontest2.ffisher.com.xmpp2 E/AndroidRuntime: java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/naming/directory/InitialDirContext;
11-10 00:41:36.169 19859-19886/xmppconnectiontest2.ffisher.com.xmpp2 E/AndroidRuntime: at org.jivesoftware.smack.util.dns.javax.JavaxResolver.<clinit>(JavaxResolver.java:50)
11-10 00:41:36.169 19859-19886/xmppconnectiontest2.ffisher.com.xmpp2 E/AndroidRuntime: at java.lang.Class.classForName(Native Method)
11-10 00:41:36.169 19859-19886/xmppconnectiontest2.ffisher.com.xmpp2 E/AndroidRuntime: at java.lang.Class.forName(Class.java:308)
as the documents of igniterealtime said I add all of necessary libraries. this is my dependencies in Gradle :
compile 'org.igniterealtime.smack:smack-core:4.1.4'
compile 'org.igniterealtime.smack:smack-tcp:4.1.4'
compile 'org.igniterealtime.smack:smack-extensions:4.1.4'
compile 'org.igniterealtime.smack:smack-resolver-javax:4.1.4'
compile 'org.igniterealtime.smack:smack-bosh:4.1.4'
compile 'org.igniterealtime.smack:smack-resolver-dnsjava:4.1.4'
compile 'org.igniterealtime.smack:smack-legacy:4.1.4'
compile 'org.igniterealtime.smack:smack-experimental:4.1.4'
compile 'org.igniterealtime.smack:smack-jingle-old:4.1.4'
compile 'org.igniterealtime.smack:smack-debug:4.1.4'
the main activity onCreate :
Thread t = new Thread(new Runnable() {
@Override
public void run() {
String [] param = {"mhs", "10.0.2.2"};
Asynchron asynchron = (Asynchron) new Asynchron();
asynchron.doInBackground(param);
}
});
t.start();
the sub class of AsyncTask that I used :
public class Asynchron extends AsyncTask <String, Void, Void>
{
@Override
protected Void doInBackground(String... params) {
XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();
builder.setServiceName(params[0]);
builder.setHost(params[1]);
builder.setPort(5222);
builder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
builder.setDebuggerEnabled(true);
builder.setCompressionEnabled(true);
connection = new XMPPTCPConnection(builder.build());
SASLAuthentication.blacklistSASLMechanism("DIGEST-MD5");
try {
connection.connect();
connection.login("testUser1", "1234");
} catch (SmackException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (XMPPException e) {
e.printStackTrace();
}
return null;
}
}
I really need your help. how can I resolve the error I wrote in title of question?
just use :
compile "org.igniterealtime.smack:smack-android-extensions:4.1.0"
compile "org.igniterealtime.smack:smack-experimental:4.1.0"
compile "org.igniterealtime.smack:smack-tcp:4.1.0"
and remove builder.setCompressionEnabled(true);
Delete smack-resolver-javax in your dependencies. Probably that jar is overriding some legacy classes
只需使用smack-tcp
, smack-experimental
和smack-android-extensions
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.