No XmlPullParserFactory registered with Service Provider Interface (SPI)

Hi,

We have and Android app and when we updated smack from 4.3.4 to 4.4.6 we started seeing crashes for some users. We didn’t change anything else.

Exception:
Caused by java.lang.IllegalStateException
No XmlPullParserFactory registered with Service Provider Interface (SPI). Is smack-xmlparser-xpp3 or smack-xmlparser-stax in classpath?

Stack trace:
org.jivesoftware.smack.xml.SmackXmlParser.getXmlPullParserFactory (SmackXmlParser.java:41)
org.jivesoftware.smack.xml.SmackXmlParser.newXmlParser (SmackXmlParser.java:65)
org.jivesoftware.smack.util.PacketParserUtils.getParserFor (PacketParserUtils.java:80)
org.jivesoftware.smack.SmackInitialization.processConfigFile (SmackInitialization.java:159)
org.jivesoftware.smack.SmackInitialization.processConfigFile (SmackInitialization.java:154)
org.jivesoftware.smack.SmackInitialization.<clinit> (SmackInitialization.java:103)
org.jivesoftware.smack.Smack.getVersion (Smack.java:38)
org.jivesoftware.smack.Smack.ensureInitialized (Smack.java:64)
org.jivesoftware.smack.ConnectionConfiguration.<clinit> (ConnectionConfiguration.java:116)
org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration.builder (XMPPTCPConnectionConfiguration.java:64)

The only thing we saw from the data we had was that this happened only for the users for which the app was started from the MediaBrowserService we implement (could be Android Auto but not sure).
We didn’t see any crash for normal app start and all our tests succeeded.

We have this in build.gradle:

implementation 'org.igniterealtime.smack:smack-android-extensions:4.4.6'
implementation 'org.igniterealtime.smack:smack-tcp:4.4.6'

configurations {
  all*.exclude group: 'xpp3', module: 'xpp3'
  all*.exclude group: 'xpp3', module: 'xpp3_min'
}

Is there something we failed to do?
Or something we can do to prevent this?

Are you sure that the required SPI implementations are in the classpath on the systems that throw this exception?

I don’t think I understand the question. All we know is that since we upgraded smack to 4.4.6 we saw in crashlytics a lot of crashes while with 4.3.4 we didn’t have any. So we had to revert to 4.3.4.
How can I find the information you need? Isn’t there a way to use smack on those devices? I mean, it worked with 4.3.4 (at least we didn’t see any reason it didn’t work).

I found a similar topic where you asked the same question and they uploaded the content of the META-INF/services. This is how our apks look like:



Do you use ProGuard or similar code obfuscation and optimization tools? If so, does the error also appear if you disable it? It is possible that those tools throw away the SPI implementations, causing this exception.

We use ProGuard but we don’t have any issues when testing on our own devices (several models and Android versions). And only some users seem to get the exception and for them the app is always started via a service.
We have these (I guess relevant) lines in the ProGuard file:

-keep class org.xmlpull.v1.** {*;}
-keep class org.jivesoftware.** { *; }

Interesting. I would need more details and probably access to your source code and the crash reports to help you further.

However, you could probably workaround it by manually invoking SmackXmlParser.setXmlPullParserFactory() early in the Service’s lifetime.

Just to be sure, you mean call it like this?
SmackXmlParser.setXmlPullParserFactory(new Xpp3XmlPullParserFactory());

When I debug SmackXmlParser.newXmlParser() I see it returning an Xpp3XmlPullParserFactory object.
So it looks like in both cases the same factory class would be used (on Android at least).
Would there be any disadvantage of using the workaround?

In any case, thank you for this solution.