powered by Jive Software

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