我正面临图书馆打ack的问题。当我将Android Studio升级到4.1,将Gradle升级到6.5时,出现如下异常:
Caused by: java.lang.AssertionError
at org.jivesoftware.smack.AbstractXMPPConnection.sendStanza(AbstractXMPPConnection.java:686)
at com.app.modules.rnxmpp.service.XmppServiceSmackImpl.sendStanza(XmppServiceSmackImpl.java:713)
at com.app.modules.rnxmpp.RNXMPPModule.sendStanza(RNXMPPModule.java:189)
在4.1和Gradle 6.0.1之前,代码没有错误,也没有崩溃。这仅在我更新Studio和Gradle时发生。
错误是由smack库中的代码引起的
//org.jivesoftware.smack.AbstractXMPPConnection
@Override
public void sendStanza(Stanza stanza) throws NotConnectedException, InterruptedException {
Objects.requireNonNull(stanza, "Stanza must not be null");
assert (stanza instanceof Message || stanza instanceof Presence || stanza instanceof IQ);
throwNotConnectedExceptionIfAppropriate();
switch (fromMode) {
case OMITTED:
stanza.setFrom((Jid) null);
break;
case USER:
stanza.setFrom(getUser());
break;
case UNCHANGED:
default:
break;
}
// Invoke interceptors for the new stanza that is about to be sent. Interceptors may modify
// the content of the stanza.
firePacketInterceptors(stanza);
sendStanzaInternal(stanza);
}
库文件AbstractXMPPConnection
中有一个断言调用
当我调用此函数时,我崩溃了,上面的堆栈跟踪记录显示在日志中。有人知道这里会发生什么吗? Android Studio版本:4.1 gradle https://services.gradle.org/distributions/gradle-6.5-bin.zip // smack库
implementation "org.igniterealtime.smack:smack-android-extensions:4.3.0"
implementation "org.igniterealtime.smack:smack-tcp:4.3.0"
implementation "org.igniterealtime.smack:smack-extensions:4.3.0"
implementation 'org.igniterealtime.smack:smack-sasl-provided:4.1.9'
答案 0 :(得分:1)
我有同样的问题。我正在使用MultipleRecipientManager
问题是我没有DomainBareJid,并且调用了sendToIndividualRecipients(...)方法。
public static void send(XMPPConnection connection, Stanza packet, Collection<? extends Jid> to, Collection<? extends Jid> cc, Collection<? extends Jid> bcc,
Jid replyTo, Jid replyRoom, boolean noReply) throws NoResponseException, XMPPErrorException, FeatureNotSupportedException, NotConnectedException, InterruptedException {
// Check if *only* 'to' is set and contains just *one* entry, in this case extended stanzas addressing is not
// required at all and we can send it just as normal stanza without needing to add the extension element
if (to != null && to.size() == 1 && (cc == null || cc.isEmpty()) && (bcc == null || bcc.isEmpty()) && !noReply
&& StringUtils.isNullOrEmpty(replyTo) && StringUtils.isNullOrEmpty(replyRoom)) {
Jid toJid = to.iterator().next();
packet.setTo(toJid);
connection.sendStanza(packet);
return;
}
DomainBareJid serviceAddress = getMultipleRecipientServiceAddress(connection);
if (serviceAddress != null) {
// Send packet to target users using multiple recipient service provided by the server
sendThroughService(connection, packet, to, cc, bcc, replyTo, replyRoom, noReply,
serviceAddress);
}
else {
// Server does not support XEP-33 so try to send the packet to each recipient
if (noReply || replyTo != null ||
replyRoom != null) {
// Some specified XEP-33 features were requested so throw an exception alerting
// the user that this features are not available
throw new FeatureNotSupportedException("Extended Stanza Addressing");
}
// Send the packet to each individual recipient
sendToIndividualRecipients(connection, packet, to, cc, bcc);
}
}
内部类PacketCopy将作为节发送。
connection.sendStanza(new PacketCopy(packet.toXML(null)));
但是AbstractXMPPConnection断言检查失败。因为PacketCopy不能从消息,状态或IQ扩展。
public void sendStanza(Stanza stanza) throws NotConnectedException, InterruptedException {
Objects.requireNonNull(stanza, "Stanza must not be null");
assert (stanza instanceof Message || stanza instanceof Presence || stanza instanceof IQ);
throwNotConnectedExceptionIfAppropriate();
switch (fromMode) {
case OMITTED:
stanza.setFrom((Jid) null);
break;
case USER:
stanza.setFrom(getUser());
break;
case UNCHANGED:
default:
break;
}
// Invoke interceptors for the new stanza that is about to be sent. Interceptors may modify
// the content of the stanza.
firePacketInterceptors(stanza);
sendStanzaInternal(stanza);
}
我的解决方案: 在更新ejabberd docker映像之前,我忘记启用了mod_multicast模块。启用mod_multicast模块之后。我有一个DomainBareJid,并且将发送正确的节类型(在我的情况下为Message)。