powered by Jive Software

Smack sendStanza function return AssertionError after upgrading Android Gradle Plugin to 4.1

After upgrading gradle version to 7.3.3 and gradle plugin to 7.2.1 my app start to get this exception

at org.jivesoftware.smack.AbstractXMPPConnection.sendStanza(AbstractXMPPConnection.java:686)

This is the relevant part in AbstractXMPPConnection.java:

    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);

My app only crashes when i upgrade gradle version and only in debug mode this happend so i searched and find this change and i think this is the problem

Assertions in debug builds

When you build the debug version of your app using Android Gradle plugin 4.1.0 and higher, the built-in compiler (D8) will rewrite your app’s code to enable assertions at compile time, so you always have assertion checks active.

So do you have any idea how i can prevent this problem?

Which Smack version is this?

I’m using version 4.3.2
After I updated smack to the latest version, nothing changed and the problem still exists

Next step would be to find out the type of the stanza instance that is triggering the assertion. To do so, attach a debugger, create a breakpoint for AssertionErrors and inspect the stanza insance that is causing the assertion to trigger to find out its type.

I create custom stanza like this

object : Stanza() {
            override fun toXML(enclosingNamespace: String?) = ""
            override fun toString() = ""

This stanza works in release mode and there is no problem, but in debug mode it creates an assertion error

Well, Smack users are not supposed to create their own subclasses of Stanza. Smack provides sufficient extension interfaces allowing users to put “their” XML on the XMPP wire.

Sorry i couldn’t find any documentation about this extension interfaces to implement my xml, can you send a link or any example how to implement it

First I would need to know what you are trying to achieve.

My xml is about querying an archive and it look like this:

<iq type='set' id='juliet1'>
  <query xmlns='urn:xmpp:mam:2'>
    <x xmlns='jabber:x:data' type='submit'>
      <field var='FORM_TYPE' type='hidden'>
      <field var='with'>
  <set xmlns='http://jabber.org/protocol/rsm'>

Any reason why you don’t use Smack’s MAM API from smackx.mam then? :slight_smile:

1 Like

Thanks for your reply, it worked for me.
Is there a general solution for all xmls?