firebase / firebase-android-sdk

Firebase Android SDK
https://firebase.google.com
Apache License 2.0
2.29k stars 579 forks source link

160996413: Firebase IAM(In-App Messaging) Crash 💣 BUG #1694

Closed PetkevichPavel closed 3 years ago

PetkevichPavel commented 4 years ago

Basic info:

Describe the problem

We created a new campaign and for some of the users, the application failed during the showing In-App Message.

Here is the crash from crashlytics:

Fatal Exception: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
       at android.view.ViewRootImpl.setView(ViewRootImpl.java:1000)
       at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:428)
       at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:118)
       at com.google.firebase.inappmessaging.display.internal.FiamWindowManager.show(FiamWindowManager.java:28)
       at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay$4$4.run(FirebaseInAppMessagingDisplay.java:14)
       at android.app.Activity.runOnUiThread(Activity.java:7178)
       at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay$4.onSuccess(FirebaseInAppMessagingDisplay.java:89)
       at com.squareup.picasso.ImageViewAction.a(ImageViewAction.java:31)
       at com.squareup.picasso.Picasso.a(Picasso.java:28)
       at com.squareup.picasso.Picasso.a(Picasso.java:50)
       at com.squareup.picasso.Picasso$1.handleMessage(Picasso.java:81)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loop(Looper.java:213)
       at android.app.ActivityThread.main(ActivityThread.java:8178)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)

Steps to reproduce:

I can give you all devices which were affected, and maybe it can be helpful for you: 33% - Galaxy S10e 17% - Galaxy S20 Ultra 5G 17% - Galaxy S20 17% - P30 Pro 16% - HUAWEI P smart 2019

Relevant Code:

Nothing to share, it was implemented according to your documentation.

google-oss-bot commented 4 years ago

I found a few problems with this issue:

JasonAHeron commented 4 years ago

Hey @PetkevichPavel thanks for letting us know, We've seen issues with the Window Manager before and I've been trying to nail them down as they come up. I'm curious, for your implementation of FIAM are you triggering FIAM and then changing back and fourth between activities? or triggering FIAM and then immediately killing the triggering activity? something like a splash screen maybe?

Are you able to reproduce this issue at all locally? If you can then the SDK debug logs would be very helpful. To enable debug logging you can do

adb shell setprop log.tag.FIAM.Headless DEBUG

PetkevichPavel commented 4 years ago

Hi @JasonAHeron , thanks for your quick reply. Unfortunately, but I'm not able to reproduce it locally... Nevertheless, according to the implementation in code, I am only adding few dependencies. But if I understood you correctly, you are talking about triggers IAM, which are based on specific events. In that case, we have predefined following events: app_launch, screen_view, on_foreground.

According to the activities: yes, you're right. I'm using as launcher activity RouterActivity. In other words, SplashScreen, after that, the user is redirected to the specific flow of the app.

And finally, I also see this problem, you're triggering IAM directly on the [app_launch&screen_view&on_foreground], but in my case is the SplashScreen and it will die quicker than the message will appear and here we go....💣

As a result maybe I know few possible solutions:

  1. SDK should provide some function with the initialization of IAM, which I will call in App.kt with some specific param such as isSplashScreen.
  2. But maybe the best one solution will be to add another one section into Firebase IAM settings, which will provide us the possibility to exclude the specific screens based on the Screen classes name or custom screen names if the developer is tracking it. Screenshot 2020-06-23 at 13 45 31

What do you think ? 😅

JasonAHeron commented 4 years ago

Thanks for the detailed response, so I actually did a lot of work to try to make this splash screen style workflow work invisibly behind the scenes without crashing. Is this coming from app that use our latest SDK version? https://firebase.google.com/support/release-notes/android#inappmessaging_v19-0-7

If this crash is coming from apps that haven't yet updated to a version depending on 19.0.7 then this issue could very well go away once the users update

PetkevichPavel commented 4 years ago

Hi @JasonAHeron, as I mentioned in the first message I am using the latest version of the SDK, thats mean that this crash is already coming from the lates version of the SDK.

JasonAHeron commented 4 years ago

Absolutely, I saw that, I just know that when you update a dependency in your app and publish it to the app store there can still be months and months of users using older versions of your app. So you're saying the crashes are coming from this version right? not just that your app is currently published from this version?

Are you seeing crashes coming from this version and not prior versions or your app with a different version of our SDK? that would also be helpful to know for tracking this down

PetkevichPavel commented 4 years ago

@JasonAHeron I double checked it right now, and yes all crashes coming from the latest build which already using the latest SDK.

JasonAHeron commented 4 years ago

okay that's really helpful, so this crash just started on the most recent version of the SDK? Did you change the way your app uses activities in this release as well? did your app exist before this release?

I can tell you one work around that will very likely stop your crashes for now as I continue to investigate this. Do not trigger fiam from an activity you are about to stop/destroy. So if you want to trigger FIAM do it from an activity which will actually stay around to display the message rather than triggering from an activity that you're about to kill off or switch from.

PetkevichPavel commented 4 years ago

@JasonAHeron I got your questions, I will try my best to describe it in one sentence: This project is the fresh deployed, and we start using IAM directly with the latest SDK version, because of that I'm not able to tell you if this bug appeared on the previous versions or not.

As for your temporary solution, currently, I didn't have any additional implementation in the code, what I'm only doing is adding the dependencies on FIAM.

But only for clarification, do you mean that I have to add this trigger FIAM programmatically? or I need to add a specific event which is referred to the particular screen(img below)?

Screenshot 2020-06-23 at 13 45 31

Thank you in advance.

PetkevichPavel commented 4 years ago

Hello @JasonAHeron, maybe you missed my previous message, nevertheless please can you react on it somehow thank you in advance.

JasonAHeron commented 4 years ago

Hey, so by trigger FIAM I mean trigger via any mechanism. It sounds like you're triggering via Firebase Analytics. So what you can do is rather than trigger based on an analytics event that you fire right before killing your activity you can trigger from an event when you start the activity that you're going to.

This is my understanding if your current setup.

Activity 1:

  1. starts up and does work,
  2. triggers analytics event (that fiam is listening for)
  3. immediately kills itself and switches to another activity

Activity 2:

  1. starts up and tries to display fiam from activity 1, crashes

you can solve this by triggering fiam from activity 2 when it starts rather than from activity 1 when it dies. Does that make sense?

Also we are aware of this and we are working on it but unfortunately I don't always have the time to update this bug with my progress. Thank you for the detailed report though and we are indeed working on it.

mzgreen commented 4 years ago

I have this issue as well. It started to show up recently (June 26th):

Fatal Exception: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
       at android.view.ViewRootImpl.setView(ViewRootImpl.java:1069)
       at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:381)
       at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)
       at com.google.firebase.inappmessaging.display.internal.FiamWindowManager.show(FiamWindowManager.java:62)
       at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay$4$4.run(FirebaseInAppMessagingDisplay.java:428)
       at android.app.Activity.runOnUiThread(Activity.java:6406)
       at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay$4.onSuccess(FirebaseInAppMessagingDisplay.java:424)
       at com.squareup.picasso.RequestCreator.into(RequestCreator.java:721)
       at com.google.firebase.inappmessaging.display.internal.FiamImageLoader$FiamImageRequestCreator.into(FiamImageLoader.java:65)
       at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay.loadNullableImage(FirebaseInAppMessagingDisplay.java:506)
       at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay.inflateBinding(FirebaseInAppMessagingDisplay.java:362)
       at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay.access$000(FirebaseInAppMessagingDisplay.java:83)
       at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay$1.run(FirebaseInAppMessagingDisplay.java:298)
       at android.os.Handler.handleCallback(Handler.java:873)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:214)
       at android.app.ActivityThread.main(ActivityThread.java:7156)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)

I'm using InAppMessaging library version 19.0.6. And it happens on different devices such as:

37% samsung
21% Xiaomi
9% motorola
9% HUAWEI
24% Other

I have a single activity app so it's a bit weird.

JasonWoodenberg commented 4 years ago

Experiencing similar issues with this bug as detailed above by @PetkevichPavel - An update on this would be great @JasonAHeron . Thanks

premacck commented 4 years ago

Similar issue is opened here: https://github.com/firebase/firebase-android-sdk/issues/1808 and https://github.com/firebase/firebase-android-sdk/issues/112

PetkevichPavel commented 3 years ago

@premacck Thank you for notice, I already reacted there.

@JasonAHeron For the last months we weren't face with this issue again, nevertheless as I see from the comments above and also duplicating issues such as #1808, probably the bug is still exist. By start of the year we are planing several campaigns which will use the IAM, and the campaigns will be on the big audience, based on those data I will be able to tell you if this bug is still actual for me or not.

Thank you in advance see you next year.

Merry Christmas & Happy New Year to all 🎊.

deepak786 commented 3 years ago

have the similar issue:

Fatal Exception: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
       at android.view.ViewRootImpl.setView(ViewRootImpl.java:935)
       at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:393)
       at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:95)
       at com.google.firebase.inappmessaging.display.internal.FiamWindowManager.show(FiamWindowManager.java:62)
       at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay$4$4.run(FirebaseInAppMessagingDisplay.java:412)
       at android.app.Activity.runOnUiThread(Activity.java:6919)
       at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay$4.onSuccess(FirebaseInAppMessagingDisplay.java:408)
       at com.squareup.picasso.ImageViewAction.complete(ImageViewAction.java:52)
       at com.squareup.picasso.Picasso.deliverAction(Picasso.java:576)
       at com.squareup.picasso.Picasso.complete(Picasso.java:528)
       at com.squareup.picasso.Picasso$1.handleMessage(Picasso.java:122)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loop(Looper.java:241)
       at android.app.ActivityThread.main(ActivityThread.java:7617)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)
Screen Shot 2021-02-09 at 2 22 16 PM

Our app latest version 2.2.3 has the following library version:

implementation 'com.google.firebase:firebase-inappmessaging-display:19.1.2'
sudharsans85 commented 3 years ago

+1 Facing same issue. When is it expected to move out of BETA

RicardAparicio commented 3 years ago

Same issue here. version 19.1.3

monsterbrain commented 3 years ago

It seems that this issue is fixed in 19.1.5 as mentioned here : https://firebase.google.com/support/release-notes/android#inappmessaging_v19-1-5

ogrenichv commented 3 years ago

I'm still seeing this issue using latest version (20.0)

vishalpatel1327 commented 3 years ago

image

having the same issue for a long time. any update on this?

At least put try-catch for now 😄

eldhosembabu commented 3 years ago

This issue should be fixed in: https://github.com/firebase/firebase-android-sdk/pull/2402

So closing this bug.

Feel free to reopen this if you were able to reproduce the issue with the latest FIAM Display SDK version. Thanks