powered by Jive Software

Exception when trying to connect - but only in release mode`

Hi all, I have a weird problem. I try to implement the most basic scenario to start, which is simply connecting to an XMPP server. I’m developing a Flutter app, from which I call into Java / Kotlin.

The thing is, this works perfectly well, as long as I run the debug version. As soon as I try the release version, I get an exception when trying to login. Has anyone any ideas? I must be doing something fundamentally wrong… I’m using Smack 4.4.6, but it’s behaving exactly the same with 4.2.0 and 4.40 . The behaviour is consistent across multiple hardware devices and happens with two different XMPP servers.

The code is simply the minimal example from the GitHub page:

AbstractXMPPConnection connection = new XMPPTCPConnection(...);
connection.connect().login();

Any help would be greatly appreciated

This is the callstack I get:

  java.lang.RuntimeException: An error occurred while executing doInBackground()
        at android.os.AsyncTask$3.done(AsyncTask.java:353)
        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
        at java.util.concurrent.FutureTask.run(FutureTask.java:271)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: java.util.ServiceConfigurationError: h8.e: Provider i8.b could not be instantiated
        at java.util.ServiceLoader.fail(ServiceLoader.java:233)
        at java.util.ServiceLoader.-wrap1(Unknown Source:0)
        at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:392)
        at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:416)
        at java.util.ServiceLoader$1.next(ServiceLoader.java:494)
        at h8.a.a(Unknown Source:17)
        at h8.a.b(Unknown Source:0)
        at d8.a0.d(Unknown Source:7)
        at a7.z.d(Unknown Source:0)
        at a7.z.c(Unknown Source:6)
        at a7.z.<clinit>(Unknown Source:97)
        at a7.u.b(Unknown Source:0)
        at a7.u.a(Unknown Source:7)
        at a7.k.<clinit>(Unknown Source:26)
        at p4.b.a(Unknown Source:5)
        at p4.b.doInBackground(Unknown Source:2)
        at android.os.AsyncTask$2.call(AsyncTask.java:333)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 
        at java.lang.Thread.run(Thread.java:764) 
     Caused by: java.lang.ExceptionInInitializerError
        at java.lang.Class.newInstance(Native Method)
        at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:388)
        at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:416) 
        at java.util.ServiceLoader$1.next(ServiceLoader.java:494) 
        at h8.a.a(Unknown Source:17) 
        at h8.a.b(Unknown Source:0) 
        at d8.a0.d(Unknown Source:7) 
        at a7.z.d(Unknown Source:0) 
        at a7.z.c(Unknown Source:6) 
        at a7.z.<clinit>(Unknown Source:97) 
        at a7.u.b(Unknown Source:0) 
        at a7.u.a(Unknown Source:7) 
        at a7.k.<clinit>(Unknown Source:26) 
        at p4.b.a(Unknown Source:5) 
        at p4.b.doInBackground(Unknown Source:2) 
        at android.os.AsyncTask$2.call(AsyncTask.java:333) 
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 
        at java.lang.Thread.run(Thread.java:764) 
     Caused by: org.xmlpull.v1.XmlPullParserException: unsupported feature: http://xmlpull.org/v1/doc/features.html#xml-roundtrip (position:START_DOCUMENT null@1:1) 
        at org.kxml2.io.KXmlParser.setFeature(KXmlParser.java:2102)
        at i8.b.<clinit>(Unknown Source:25)
        at java.lang.Class.newInstance(Native Method) 
        at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:388) 
        at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:416) 
        at java.util.ServiceLoader$1.next(ServiceLoader.java:494) 
        at h8.a.a(Unknown Source:17) 
        at h8.a.b(Unknown Source:0) 
        at d8.a0.d(Unknown Source:7) 
        at a7.z.d(Unknown Source:0) 
        at a7.z.c(Unknown Source:6) 
        at a7.z.<clinit>(Unknown Source:97) 
        at a7.u.b(Unknown Source:0) 
        at a7.u.a(Unknown Source:7) 
        at a7.k.<clinit>(Unknown Source:26) 
        at p4.b.a(Unknown Source:5) 
        at p4.b.doInBackground(Unknown Source:2) 
        at android.os.AsyncTask$2.call(AsyncTask.java:333) 
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 
        at java.lang.Thread.run(Thread.java:764)

Do you use a custom variant of Smack’s Xpp3XmlPullParserFactory? Because the vanilla variant simply logs the fact that XPP3 does not support xml-roundtrip, whereas the stacktrace appears to indicate that the exception is further propagated. But it impossible to tell what is really going on with the provided information and that the code is obfuscated makes it even harder.

What is the code at i8.b.(Unknown Source:25)? That does not appear to be Smack.

Does producing the release version involve some kind of code obfuscation process?

Hi guys thanks so much for coming back to me. Flutter indeed seems to do some stuff during the build process I have yet to figure out.

The weird thing is, everything works like a charm in debug AND profile mode, but not in release.

I also made a minimal sample project in vanilla Android and there everything is fine, regardless of debug or release mode.

So it seems to be some sort of flutter thing. I try to gather more infirmation from them.

1 Like

I’ve done some more research. The Android build contains a ProGuard step, which, as far as I understand it, minifies the code, obfuscates and optimizes it.

I’ve disabled that step completely, in order to gather more infomration about the stack trace and voila - it stops crashing. On the other hand, I can bring back the obfuscated parts of the stacktrace by just excluding the smack part from the ProGuard step. In that case, it still crashes and gives me this:

FATAL EXCEPTION: main
    Process: com.example.release_exception, PID: 1283
    java.util.ServiceConfigurationError: org.jivesoftware.smack.xml.XmlPullParserFactory: Provider org.jivesoftware.smack.xml.xpp3.Xpp3XmlPullParserFactory could not be instantiated
        at java.util.ServiceLoader.fail(ServiceLoader.java:233)
        at java.util.ServiceLoader.access$100(ServiceLoader.java:183)
        at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:392)
        at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:416)
        at java.util.ServiceLoader$1.next(ServiceLoader.java:494)
        at org.jivesoftware.smack.xml.SmackXmlParser.getXmlPullParserFactory(Unknown Source:17)
        at org.jivesoftware.smack.xml.SmackXmlParser.newXmlParser(Unknown Source:0)
        at org.jivesoftware.smack.util.PacketParserUtils.getParserFor(Unknown Source:7)
        at org.jivesoftware.smack.SmackInitialization.processConfigFile(Unknown Source:0)
        at org.jivesoftware.smack.SmackInitialization.processConfigFile(Unknown Source:6)
        at org.jivesoftware.smack.SmackInitialization.<clinit>(Unknown Source:97)
        at org.jivesoftware.smack.Smack.getVersion(Unknown Source:0)
        at org.jivesoftware.smack.Smack.ensureInitialized(Unknown Source:7)
        at org.jivesoftware.smack.AbstractXMPPConnection.<clinit>(Unknown Source:26)
        at com.example.release_exception.MainActivity.C(Unknown Source:14)
        at io.flutter.embedding.android.e.p(Unknown Source:58)
        at io.flutter.embedding.android.d.onCreate(Unknown Source:13)
        at android.app.Activity.performCreate(Activity.java:7327)
        at android.app.Activity.performCreate(Activity.java:7318)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3094)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3257)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7050)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
     Caused by: java.lang.ExceptionInInitializerError
        at java.lang.Class.newInstance(Native Method)
        at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:388)
        at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:416) 
        at java.util.ServiceLoader$1.next(ServiceLoader.java:494) 
        at org.jivesoftware.smack.xml.SmackXmlParser.getXmlPullParserFactory(Unknown Source:17) 
        at org.jivesoftware.smack.xml.SmackXmlParser.newXmlParser(Unknown Source:0) 
        at org.jivesoftware.smack.util.PacketParserUtils.getParserFor(Unknown Source:7) 
        at org.jivesoftware.smack.SmackInitialization.processConfigFile(Unknown Source:0) 
        at org.jivesoftware.smack.SmackInitialization.processConfigFile(Unknown Source:6) 
        at org.jivesoftware.smack.SmackInitialization.<clinit>(Unknown Source:97) 
        at org.jivesoftware.smack.Smack.getVersion(Unknown Source:0) 
        at org.jivesoftware.smack.Smack.ensureInitialized(Unknown Source:7) 
        at org.jivesoftware.smack.AbstractXMPPConnection.<clinit>(Unknown Source:26) 
        at com.example.release_exception.MainActivity.C(Unknown Source:14) 
        at io.flutter.embedding.android.e.p(Unknown Source:58) 
        at io.flutter.embedding.android.d.onCreate(Unknown Source:13) 
        at android.app.Activity.performCreate(Activity.java:7327) 
        at android.app.Activity.performCreate(Activity.java:7318) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3094) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3257) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.app.ActivityThread.main(ActivityThread.java:7050) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965) 
     Caused by: org.xmlpull.v1.XmlPullParserException: unsupported feature: http://xmlpull.org/v1/doc/features.html#xml-roundtrip (position:START_DOCUMENT null@1:1) 
        at org.kxml2.io.KXmlParser.setFeature(KXmlParser.java:2102)
        at org.jivesoftware.smack.xml.xpp3.Xpp3XmlPullParserFactory.<clinit>(Unknown Source:25)
        at java.lang.Class.newInstance(Native Method) 
        at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:388) 
        at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:416) 
        at java.util.ServiceLoader$1.next(ServiceLoader.java:494) 
        at org.jivesoftware.smack.xml.SmackXmlParser.getXmlPullParserFactory(Unknown Source:17) 
        at org.jivesoftware.smack.xml.SmackXmlParser.newXmlParser(Unknown Source:0) 
        at org.jivesoftware.smack.util.PacketParserUtils.getParserFor(Unknown Source:7) 
        at org.jivesoftware.smack.SmackInitialization.processConfigFile(Unknown Source:0) 
        at org.jivesoftware.smack.SmackInitialization.processConfigFile(Unknown Source:6) 
        at org.jivesoftware.smack.SmackInitialization.<clinit>(Unknown Source:97) 
        at org.jivesoftware.smack.Smack.getVersion(Unknown Source:0) 
        at org.jivesoftware.smack.Smack.ensureInitialized(Unknown Source:7) 
        at org.jivesoftware.smack.AbstractXMPPConnection.<clinit>(Unknown Source:26) 
        at com.example.release_exception.MainActivity.C(Unknown Source:14) 
        at io.flutter.embedding.android.e.p(Unknown Source:58) 
        at io.flutter.embedding.android.d.onCreate(Unknown Source:13) 
        at android.app.Activity.performCreate(Activity.java:7327) 
        at android.app.Activity.performCreate(Activity.java:7318) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3094) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3257) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.app.ActivityThread.main(ActivityThread.java:7050) ```

if there’s anything else I can try, please let me know…

I think I finally solved it. Proguard definitely messes things up and these rules make it work for me:

-keep class org.jivesoftware.** { *; }
-keep class org.xmlpull.** { *; }
-keep class org.bouncycastle.jcajce.provider.** { *; }

I hope this is of some help to others with a similar situation

1 Like