更新到 Android Studio 4.1 时出现 java.lang.AssertionError
Posted
技术标签:
【中文标题】更新到 Android Studio 4.1 时出现 java.lang.AssertionError【英文标题】:java.lang.AssertionError when update to Android studio 4.1 【发布时间】:2020-10-19 08:08:15 【问题描述】:我正面临图书馆 smack 的问题。当我将 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 之前,代码没有错误,也没有任何崩溃。这只发生在我更新工作室和 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
的库文件中有一个断言调用
当我调用这个函数时,我遇到了崩溃,上面的堆栈跟踪显示在日志上。有谁知道这里发生了什么? 安卓工作室版本:4.1 毕业 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'
【问题讨论】:
错误解决了吗? 没有。我现在正在使用 Gradle-6.1.1。如果我更改为 6.5 则会出现此错误 【参考方案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 不是从 Message、Presence 或 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 并且将发送正确的 Stanza 类型(在我的情况下为 Message)。
【讨论】:
我正在使用 Ejabberd SASS。所以我什么都改变不了。此代码在 Gradle 6.1.1 上运行良好。如果我更新到 6.5,我就会遇到问题以上是关于更新到 Android Studio 4.1 时出现 java.lang.AssertionError的主要内容,如果未能解决你的问题,请参考以下文章
更新到 Android Studio 4.1,flutter 插件和 dart 插件未安装
Android Studio 4.1更新后应用程序的Gradle构建错误
Flutter Doctor 不识别 Android Studio 和 flutter dart plugins plugins 新版本 4.1 更新
在Android Studio中更新Android SDK API 28时出现问题
随着 Android Studio 4.1 更新 'Plugin incompatible with the new build found: Firebase Services' 出现警告信息