customerio / customerio-flutter

Flutter plugin for Customer.io
https://www.customer.io/docs/sdk/flutter/getting-started/
MIT License
12 stars 10 forks source link

GistSdk.getSiteId k.q - lateinit property siteId has not been initialized #98

Closed msalman2890 closed 10 months ago

msalman2890 commented 11 months ago

I have integrated customer io flutter sdk in my app and it is crashing on android suddenly for our production users and firebase crashlytics logged the following stack trace.

Package name: io.customer.messaginginapp.gist.presentation File name: GistSdk.java:7

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{/io.customer.messaginginapp.gist.presentation.GistModalActivity}: k.q: lateinit property siteId has not been initialized at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3676) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3813) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2308) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7898) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

Caused by k.q: lateinit property siteId has not been initialized at io.customer.messaginginapp.gist.presentation.GistSdk.getSiteId(GistSdk.java:7) at io.customer.messaginginapp.gist.presentation.GistView.setup(:15) at io.customer.messaginginapp.gist.presentation.GistModalActivity.onCreate(GistModalActivity.java:136) at android.app.Activity.performCreate(Activity.java:8290) at android.app.Activity.performCreate(Activity.java:8269) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1384) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3657) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3813) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2308) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7898) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

mrehan27 commented 11 months ago

Hi @msalman2890. Sorry to hear about the problem you are facing. Can you give more details on the issue? Do you have steps or a specific scenario that triggers it? Also, are you initializing the SDK at app launch, or is there a delay in its initialization? Lastly, could you let us know which SDK version you're using when this crash occurs?

msalman2890 commented 11 months ago

It's just a random issue on production and faced by few users out of thousands but still it is occurring suddenly. This issue is facing by Android users at the moment and no IOS users are affected.

SDK is initialized after splash screen and I am using plugin version 1.2.4

mrehan27 commented 11 months ago

Thank you for the details. Is there a scenario where the app is opened but the SDK isn't initialized? Our recommendation is to initialize the SDK at the root component as early as possible, allowing it to set up necessary listeners and carry out operations timely. Please refer to our sample app for reference. Updating to the latest SDK version and initializing SDK at the root should resolve this issue. Let us know if the problem persists.

levibostian commented 10 months ago

Closing issue due to inactivity.

Feel free to add new comments and we would be happy to re-open and help.

nikorehnback commented 2 months ago

We are seeing this as well using Flutter lib version:

customer_io: ^1.5.0

@levibostian any ideas how we can help you team to resolve the crash?

levibostian commented 2 months ago

Sorry to hear you're experiencing this issue as well, @nikorehnback. Would be happy to look into this with you.

If you have a stacktrace for the crash, is it identical to the one in this issue description? If not, we would appreciate opening a new github issue.

Assuming that the stacktrace is identical, we do have a few questions that would help us to debug this issue. Our team has not been able to reproduce the issue yet. The more information that can be provided to help us do that is very helpful!

Hope you have an awesome day. Thank you for your time!

nikorehnback commented 2 months ago

hey @levibostian. The trace is identical, my hypothesis is that it's somehow related to push notifications sine we have our own extended FirebaseMessagingService.

We will rollout a test that we initialize Customer.IO also in Android Application onCreate to see if that helps. Do you see any risks of initializing the Customer.IO SDK in Android native side and then again in Flutter side using your SDK?

levibostian commented 2 months ago

Although I do not anticipate problems with initializing the SDK in the native side and the Flutter side, it is a pattern that is not common for our Flutter customers. Therefore, it's not well tested and we do not suggest shipping that change to production.

If you could share more details about why you believe that push notifications could be causing this issue, please send it to us. The more details, the better to be able to reproduce this.

nikorehnback commented 2 months ago

I was thinking if it could be something that push message triggers and Flutter app is not created yet where the SDK init itself happens, but if you think that shouldn't be the case, perhaps we don't even try this workaround hack at all.

levibostian commented 1 month ago

push message triggers and Flutter app is not created yet where the SDK init itself happens

If you're able to reproduce this behavior, then this would be very helpful information to us. I think this is worth the workaround hack that you mention.

nikorehnback commented 1 month ago

Wasn't able to reproduce this, any ideas when new CustomerIO Flutter lib available? There looks to be many CustomerIO Android SDK releases made

levibostian commented 1 month ago

We have not been able to reproduce this as well. Really frustrating bug here! Thank you very much for trying to help.

We do not plan on making a Flutter Android release upgrade at this time. The existing 3.11.0 is new and includes the most recent bug fixes relevant for Flutter customers.

The Android SDK has recently gotten a v4 release that we do plan on installing in the Flutter SDK. Unfortunately, we do have a release date to share.

nikorehnback commented 1 month ago

@levibostian any thoughts if scenario something like below could happen?

  1. GistModalActivity is created
  2. App is terminated but remains Activities remain in history
  3. App opened again
  4. Flutter MainActivity and GistModalActivity gets created (Dart main not executed yet to initialize Customer.io)
  5. GistModalActivity crashes in view setup trying to access GistSdk.siteId
nikorehnback commented 1 month ago

Instead of crashing, could there be safety added to GistModalActivity to e.g. log warning?

nikorehnback commented 1 month ago

@levibostian thoughts of making lateinit members optional and silently failing instead of crashing?

Shahroz16 commented 1 month ago

Hey @nikorehnback, thank you for reaching out, we are working on this and would be moving away from lateinit.

donpaul120 commented 3 weeks ago

@Shahroz16 please, any idea if this is getting fixed soonest ?

Shahroz16 commented 3 weeks ago

@donpaul120 Yes, we are actively working on it, this requires a bit of work but it's being worked on at this moment.