Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AppStartTrace.onActivityResumed : java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewTreeObserver android.view.View.getViewTreeObserver()' on a null object reference #6367

Open
aboulianne-ludia opened this issue Oct 10, 2024 · 1 comment

Comments

@aboulianne-ludia
Copy link

[REQUIRED] Step 2: Describe your environment

  • Firebase Component: Performance
  • Component version: 20.5.1
  • Other Firebase components used: Analytics, Crashlytics, DynamicLinks, Messaging
  • (several other third party plugins for ads, authentication, customer support)
  • Unity 2022.3.27f1 but happened with previous versions as well.

[REQUIRED] Step 3: Describe the problem

In our live app built with Unity (2022.3.27f1), our top crash (600 events daily but less than 1% of our sessions) used to happen when our UnityPlayerActivity would receive onResume. (call stack will be shown below).
Looking at the code of AppStartTrace.java at line 355 (at revision a350561 on April 25th, 2024 ), the line is:

353    if (isExperimentTTIDEnabled) {
354      View rootView = activity.findViewById(android.R.id.content);
355      rootView.getViewTreeObserver().addOnDrawListener(onDrawCounterListener);  // crash happens here

It is unclear why, in certain cases, line 354 would return null.
The crash disappeared when we disabled ExperimentTTID by adding
<meta-data android:name="experiment_app_start_ttid" android:value="false" />
to our AndroidManifest.xml

We have never reproduced the issue internally, or never noticed that it happened.
It seems to happen on Android 12 and above.

Would a null check against rootView resolve the issue? Or is there a deeper reason and that value should never be null?
Since our app is large, maybe the view hasn't finished initialization at that point? (Google Play vitals has flagged our Warm app start metric as problematic, if that helps.)

Steps to reproduce:

truncated call stack of crash:

Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewTreeObserver android.view.View.getViewTreeObserver()' on a null object reference
       at com.google.firebase.perf.metrics.AppStartTrace.onActivityResumed(AppStartTrace.java:355)
       at android.app.Application.dispatchActivityResumed(Application.java:436)
       at android.app.Activity.dispatchActivityResumed(Activity.java:1489)
       at android.app.Activity.onResume(Activity.java:2081)
       at com.unity3d.player.UnityPlayerActivity.onResume(UnityPlayerActivity.java:97)

Relevant Code:

@lehcar09
Copy link
Contributor

Hi @aboulianne-ludia, thank you for reaching out. I tried reproducing the issue, however, I did not encounter the crash. With the metrics you shared and given that this is difficult to reproduce, this seems to be an edge case scenario.

I'll raise this to our engineers with the possible fix you raised (Adding null check on the rootView element) and see what we can do here. Thanks!

lehcar09 added a commit to lehcar09/firebase-android-sdk that referenced this issue Oct 11, 2024
lehcar09 added a commit to lehcar09/firebase-android-sdk that referenced this issue Oct 11, 2024
lehcar09 added a commit to lehcar09/firebase-android-sdk that referenced this issue Oct 11, 2024
lehcar09 added a commit to lehcar09/firebase-android-sdk that referenced this issue Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants