gpt4 book ai didi

java - 从安卓连接到 XMPP 服务器

转载 作者:太空宇宙 更新时间:2023-11-03 10:39:56 25 4
gpt4 key购买 nike

如果我将 eclipse 中的类作为 java 应用程序运行,则相同的代码可以正常工作,但是当我在 android studio 中使用相同的类时,我会收到以下 RuntimeException

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

日志:

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.<init>(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.<init>(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

我被困在这里,真的不明白问题是什么。有帮助的人吗?

最佳答案

你好,如果你想为工作室更新你的库,这是一个很好的选择,但如果你也想在工作室中使用相同的代码,那么你可以访问此代码 here并检查你做的是否正确。ssl 权限的一些问题在这里检查正确的方式

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<String> arg0) {
Log.d("deb", "ug");
}

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

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

谢谢

希望对您有所帮助。

关于java - 从安卓连接到 XMPP 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35933181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com