No non-anonymous SASL authentication mechanism available in android

I am trying to build an android app using smack 4.1 beta1. When I try to login I am getting the following exception in the android app.

2381-2381/sample.app W/SASLAuthentication﹕ Server did not report any SASL mechanisms

2381-2381/sample.app W/System.err﹕ org.jivesoftware.smack.SmackException: No non-anonymous SASL authentication mechanism available

2381-2381/sample.app W/System.err﹕ at org.jivesoftware.smack.tcp.XMPPTCPConnection.loginNonAnonymously(XMPPTCPConnect ion.java:332)

2381-2381/sample.app W/System.err﹕ at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java :445)

2381-2381/sample.app W/System.err﹕ at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java :422)

2381-2381/sample.app W/System.err﹕ at sample.app.service.MessageService.onCreate(MessageService.java:107)

2381-2381/sample.app W/System.err﹕ at android.app.ActivityThread.handleCreateService(ActivityThread.java:2731)

2381-2381/sample.app W/System.err﹕ at android.app.ActivityThread.access$1800(ActivityThread.java:144)

2381-2381/sample.app W/System.err﹕ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1361)

2381-2381/sample.app W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:102)

2381-2381/sample.app W/System.err﹕ at android.os.Looper.loop(Looper.java:135)

2381-2381/sample.app W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5221)

2381-2381/sample.app W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)

2381-2381/sample.app W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)

2381-2381/sample.app W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)

2381-2381/sample.app W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

I tried listing the registered SASL mechanisms using SASLAuthentication.getRegisterdSASLMechanisms() but the list is empty.

When I try this in a stand alone program it works and I get a list of registered SASL mechanisms aswell

Did you follow the instructions mentioned in Smack’s 4.1 Readme?

I did. Except for the gradle dependency for android I dont know if there is anything else.

No, that’s basically it.

Set SmackConfiguration.DEBUG to true and show us the XML exchanged between Smack and the server. Note that it may contain sensible information that you want to eradicate first.

My bad I was not calling XMPPTCPConnection.connect() before login.

Looks like there a few bugs in login methods

  1. XMPPTCPConnection.login(userName, passWord) method does not throw a NotConnectedException even though XMPPTCPConnection.connect() was not called. It throws the exception mentioned in the original question.

  2. XMPPTCPConnection.login() when called before calling XMPPTCPConnection.connect() throws the following inappropriate exception

java.lang.RuntimeException: Unable to create service sample.app.service.MessageService: java.lang.NullPointerException: Attempt to invoke virtual method ‘void org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.throwNotConnectedExce ptionIfDoneAndResumptionNotPossible()’ on a null object reference

at android.app.ActivityThread.handleCreateService(ActivityThread.java:2741)

at android.app.ActivityThread.access$1800(ActivityThread.java:144)

at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1361)

at android.os.Handler.dispatchMessage(Handler.java:102)

at android.os.Looper.loop(Looper.java:135)

at android.app.ActivityThread.main(ActivityThread.java:5221)

at java.lang.reflect.Method.invoke(Native Method)

at java.lang.reflect.Method.invoke(Method.java:372)

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method ‘void org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.throwNotConnectedExce ptionIfDoneAndResumptionNotPossible()’ on a null object reference

at org.jivesoftware.smack.tcp.XMPPTCPConnection.throwNotConnectedExceptionIfApprop riate(XMPPTCPConnection.java:297)

at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java :395)

at sample.app.service.MessageService.onCreate(MessageService.java:131)

at android.app.ActivityThread.handleCreateService(ActivityThread.java:2731)

at android.app.ActivityThread.access$1800(ActivityThread.java:144)

at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1361)

at android.os.Handler.dispatchMessage(Handler.java:102)

at android.os.Looper.loop(Looper.java:135)

at android.app.ActivityThread.main(ActivityThread.java:5221)

at java.lang.reflect.Method.invoke(Native Method)

at java.lang.reflect.Method.invoke(Method.java:372)

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

Thanks for reporting. Fixed with Throw NotConnectedException on login() · 6d7f390 · Flowdalic/Smack · GitHub

The fix is available in Smack 4.1.0-beta2-SNAPSHOT.

1 Like

Awesome. Thanks for the great support