question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Suspiciously short list of threads when recording ANRError as Crashlytics non-fatal exception

See original GitHub issue

Hi!

I integrated ANR-WatchDog to a Unity game using custom implementation of UnityPlayerActivity.

At first I released a game with the default behaviour of the ANR-WatchDog. My app crashed due to unhandled ANRError and Firebase Crashlytics recorded something around 40 threads at this moment including UnityMain thread and others. I used setReportMainThreadOnly() because Crashlytics collects all threads by itself on fatal errors.

Then I turned this crash to a non-fatal using this code:

    @Override protected void onCreate(Bundle savedInstanceState)
    {
        ANRWatchDog watchDog = new ANRWatchDog();
        watchDog.setANRListener(new ANRWatchDog.ANRListener() {
            @Override
            public void onAppNotResponding(ANRError error) {
                FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
                crashlytics.recordException(error);
            }
        });
        watchDog.start();

        super.onCreate(savedInstanceState);
    }

This code records ANRError as a non-fatal exception and Crashlytics attaches stack traces contained in ANRError. That is why you do not see setReportMainThreadOnly() here any more. But now crash reports a very short, containing only 8-10 threads. What is strange there were no UnityMain thread while this non-fatal was triggered in the middle of a gameplay.

Please help, any ideas on how to get full list of stack traces attached?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

3reactions
AntonPetrov83commented, Feb 17, 2022

Inside the Unity game loop I tried delaying stuff with System.Threading.Thread.Sleep(6000); but to no avail. Nothing gets triggered. Maybe blocking the Unity game loop does not cause ANRs?

Yeah, ANR triggers only when main thread is blocked and Unity runs on Unity-Main thread which is not main )) To emulate an ANR you can use code:

public class AndroidShowStopper : MonoBehaviour
{
    private static bool _stop;

    public static void Stop()
    {
        _stop = true;
    }
    
#if UNITY_ANDROID
    void Update()
    {
        if (_stop)
        {
            AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
            activity.Call("runOnUiThread", new AndroidJavaRunnable(runOnUiThread));
            
            _stop= false;
        }
    }

    void runOnUiThread()
    {
        Debug.Log("I'm running on the Java UI thread!");

        while (true);
    }
#endif
}

Just call AndroidShowStopper.Stop(); somewhere.

0reactions
WaheedRashadcommented, Sep 5, 2022

Hi!

I integrated ANR-WatchDog to a Unity game using custom implementation of UnityPlayerActivity.

At first I released a game with the default behaviour of the ANR-WatchDog. My app crashed due to unhandled ANRError and Firebase Crashlytics recorded something around 40 threads at this moment including UnityMain thread and others. I used setReportMainThreadOnly() because Crashlytics collects all threads by itself on fatal errors.

Then I turned this crash to a non-fatal using this code:

    @Override protected void onCreate(Bundle savedInstanceState)
    {
        ANRWatchDog watchDog = new ANRWatchDog();
        watchDog.setANRListener(new ANRWatchDog.ANRListener() {
            @Override
            public void onAppNotResponding(ANRError error) {
                FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
                crashlytics.recordException(error);
            }
        });
        watchDog.start();

        super.onCreate(savedInstanceState);
    }

This code records ANRError as a non-fatal exception and Crashlytics attaches stack traces contained in ANRError. That is why you do not see setReportMainThreadOnly() here any more. But now crash reports a very short, containing only 8-10 threads. What is strange there were no UnityMain thread while this non-fatal was triggered in the middle of a gameplay.

Please help, any ideas on how to get full list of stack traces attached?

How to integrate ANR-WatchDog to a Unity game using custom implementation of UnityPlayerActivity?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Log Non-fatal errors on Crashlytics - android - Stack Overflow
What I do in order to report a non-fatal issue is to log an exception using the following code (remember you can throw...
Read more >
Debug your Android app based on ANR tags in the ... - Firebase
We analyze ANRs, and then, in the Crashlytics dashboard, we tag applicable threads to provide hints on how to debug the ANR. The...
Read more >
Part 4: capturing non-fatal Android errors - Bugsnag
Part 4 of everything you ever wanted to know about error handling on Android - capturing non-fatal Android errors.
Read more >
ANR-WatchDog - bytemeta
anr debug exception please help me. anjalsaneen ... Suspiciously short list of threads when recording ANRError as Crashlytics non-fatal exception. tovchenko.
Read more >
Boost your Crashlytics reports with custom keys & log messages
Custom keys help you get the specific state of your app leading up to a crash or non-fatal. You can associate arbitrary key/value...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found