Android Api 19 Initializer Error

Smack Version: 4.4.0

Stacktrace: The exception appear when I initialize an XMPPTCPConnection on Android with api level 19. I don’t have any problem when I run my app in upper versions

E/AndroidRuntime: FATAL EXCEPTION: DefaultDispatcher-worker-1
    Process: com.planout.app.debug, PID: 7026
    java.lang.ExceptionInInitializerError
        at org.jivesoftware.smack.Smack.getVersion(Smack.java:36)
        at org.jivesoftware.smack.Smack.ensureInitialized(Smack.java:50)
        at org.jivesoftware.smack.AbstractXMPPConnection.<clinit>(AbstractXMPPConnection.java:174)
        at es.planout.android.data.network.messaging.BaseSmackService.<init>(BaseSmackService.kt:48)
        at es.planout.android.data.network.messaging.SmackService.<init>(SmackService.kt:34)
        at es.planout.android.data.di.NetworkModuleKt$networkModule$1$1.invoke(NetworkModule.kt:13)
        at es.planout.android.data.di.NetworkModuleKt$networkModule$1$1.invoke(NetworkModule.kt)
        at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:50)
        at org.koin.core.instance.SingleInstanceFactory.create(SingleInstanceFactory.kt:40)
        at org.koin.core.instance.SingleInstanceFactory.get(SingleInstanceFactory.kt:48)
        at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(InstanceRegistry.kt:87)
        at org.koin.core.scope.Scope.resolveInstance(Scope.kt:214)
        at org.koin.core.scope.Scope.get(Scope.kt:181)
        at es.planout.android.app.PlanOutApp$$special$$inlined$inject$1.invoke(ComponentCallbackExt.kt:51)
        at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:81)
        at es.planout.android.app.PlanOutApp.getSmackService(PlanOutApp.kt)
        at es.planout.android.app.PlanOutApp.loginService(PlanOutApp.kt:119)
        at es.planout.android.app.PlanOutApp$onAppForegrounded$1.invokeSuspend(PlanOutApp.kt:159)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:738)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
     Caused by: java.lang.IllegalStateException: Could not parse Smack configuration file
        at org.jivesoftware.smack.SmackInitialization.<clinit>(SmackInitialization.java:106)
        at org.jivesoftware.smack.Smack.getVersion(Smack.java:36) 
        at org.jivesoftware.smack.Smack.ensureInitialized(Smack.java:50) 
        at org.jivesoftware.smack.AbstractXMPPConnection.<clinit>(AbstractXMPPConnection.java:174) 
        at es.planout.android.data.network.messaging.BaseSmackService.<init>(BaseSmackService.kt:48) 
        at es.planout.android.data.network.messaging.SmackService.<init>(SmackService.kt:34) 
        at es.planout.android.data.di.NetworkModuleKt$networkModule$1$1.invoke(NetworkModule.kt:13) 
        at es.planout.android.data.di.NetworkModuleKt$networkModule$1$1.invoke(NetworkModule.kt) 
        at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:50) 
        at org.koin.core.instance.SingleInstanceFactory.create(SingleInstanceFactory.kt:40) 
        at org.koin.core.instance.SingleInstanceFactory.get(SingleInstanceFactory.kt:48) 
        at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(InstanceRegistry.kt:87) 
        at org.koin.core.scope.Scope.resolveInstance(Scope.kt:214) 
        at org.koin.core.scope.Scope.get(Scope.kt:181) 
        at es.planout.android.app.PlanOutApp$$special$$inlined$inject$1.invoke(ComponentCallbackExt.kt:51) 
        at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:81) 
        at es.planout.android.app.PlanOutApp.getSmackService(PlanOutApp.kt) 
        at es.planout.android.app.PlanOutApp.loginService(PlanOutApp.kt:119) 
        at es.planout.android.app.PlanOutApp$onAppForegrounded$1.invokeSuspend(PlanOutApp.kt:159) 
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) 
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56) 
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571) 
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:738) 
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678) 
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665) 
     Caused by: java.lang.IllegalStateException: No XmlPullParserFactory registered with Service Provider Interface (SPI). Is smack-xmlparser-xpp3 or smack-xmlparser-stax in classpath?
        at org.jivesoftware.smack.xml.SmackXmlParser.getXmlPullParserFactory(SmackXmlParser.java:34)
        at org.jivesoftware.smack.xml.SmackXmlParser.newXmlParser(SmackXmlParser.java:54)
        at org.jivesoftware.smack.util.PacketParserUtils.getParserFor(PacketParserUtils.java:80)
        at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:159)
        at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:154)
        at org.jivesoftware.smack.SmackInitialization.<clinit>(SmackInitialization.java:103)
        at org.jivesoftware.smack.Smack.getVersion(Smack.java:36) 
        at org.jivesoftware.smack.Smack.ensureInitialized(Smack.java:50) 
        at org.jivesoftware.smack.AbstractXMPPConnection.<clinit>(AbstractXMPPConnection.java:174) 
        at es.planout.android.data.network.messaging.BaseSmackService.<init>(BaseSmackService.kt:48) 
        at es.planout.android.data.network.messaging.SmackService.<init>(SmackService.kt:34) 
        at es.planout.android.data.di.NetworkModuleKt$networkModule$1$1.invoke(NetworkModule.kt:13) 
        at es.planout.android.data.di.NetworkModuleKt$networkModule$1$1.invoke(NetworkModule.kt) 
        at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:50) 
        at org.koin.core.instance.SingleInstanceFactory.create(SingleInstanceFactory.kt:40) 
        at org.koin.core.instance.SingleInstanceFactory.get(SingleInstanceFactory.kt:48) 
        at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(InstanceRegistry.kt:87) 
        at org.koin.core.scope.Scope.resolveInstance(Scope.kt:214) 
        at org.koin.core.scope.Scope.get(Scope.kt:181) 
        at es.planout.android.app.PlanOutApp$$special$$inlined$inject$1.invoke(ComponentCallbackExt.kt:51) 
        at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:81) 
        at es.planout.android.app.PlanOutApp.getSmackService(PlanOutApp.kt) 
        at es.planout.android.app.PlanOutApp.loginService(PlanOutApp.kt:119) 
        at es.planout.android.app.PlanOutApp$onAppForegrounded$1.invokeSuspend(PlanOutApp.kt:159) 
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) 
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56) 
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571) 
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:738) 
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678) 
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)

I had similar problem in 4.3.5 but I solved with some proguard rules.

-keep class org.jivesoftware.smack.initializer.SmackInitializer
-keep class org.jivesoftware.smack.initializer.VmArgInitializer
-keep class org.jivesoftware.** { *;}
-keepclassmembers enum * {*;}

Thank you in advance

Does the problem disappear if you disable ProGuard/R8’s minification feature? If so, then it is likely because there are classes removed that should not be removed.

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

Most likely classes related to Smack’s XML pull parser abstraction. You want to keep all classes that are an instance of org.jivesoftware.smack.xml.XmlPullParserFActory and the resources of smack-xmlparser-xpp3.

If I disable ProGuard/R8’s minification feature the problem only disappear in android versions upper than 19. In api version 19, the problem still occurs.

This is my proguard rules for this project:

-keep class org.jivesoftware.smack.initializer.VmArgInitializer
-keep class org.jivesoftware.** { *;}
-keepclassmembers enum * {*;}

Could you check if the smack-xmlparser-xpp3 SPI resource is in classpath?

Yes, it is.

I see. The next thing I would do is to use an debugger and break at

to find out where the SPI initialization goes wrong.

It’s imposible to use debugger in this line. In Android versions upper level 19, if I use debugger it works, maybe a race condition?

In android 19, it never works.

Sorry for the delay

After all, I found a solution for Android upper dan Api 19, using this pro-guard rules:

-keep class org.jivesoftware.smack.initializer.VmArgInitializer
-keep class org.jivesoftware.** { *;}
-keepclassmembers enum * {*;}
-keep class org.jivesoftware.smack.** { *; }
-keep class org.jivesoftware.smackx.** { *; }

-keep class org.xmlpull.** { *; }
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod

But, in Android Api level 19, I couldn’t find a solution

Thank you for all @Flow ,
Best Regards

I think I found the root problem. This error is happen because my app need to use Multidex.

It seems that Service Loader needs that Xpp3ParserFactory where located in classes.dex instead of classesN.dex

Its my suppos, I didn’t get to run it in Android 19 still.

I am using this dex-config to avoid this situation, but it doesn’t work.

https://developer.android.com/studio/build/multidex?hl=es-419#multidexkeepproguard-property

-keep class org.jivesoftware.smack.xml.xpp3.Xpp3XmlPullParserFactory

-keep class org.jivesoftware.smack.xml.XmlPullParserFactory
-keep class org.jivesoftware.smack.xml.** { *; }
-keep class org.jivesoftware.smack.xml.xpp3.** { *; }
-keep class org.xmlpull.v1.** { *; }
-keep class org.xml.sax.** { *; }

I appreciate any help.

Thank you!

Smack 4.4.2 will include support for manually overrides of the XmlPullParserFactory. This will allow you to set the factory in a static block before SmackConfiguration is initialized and requests the first parser to be factored.

Nice news for me!

I will be waiting for it!

Thank you for all!

Best Regards,

No need to wait, it’s already available via Ignite’s archiva

https://www.igniterealtime.org/archiva/

This topic was automatically closed 62 days after the last reply. New replies are no longer allowed.