Android Studio missing exception stacktrace in Logcat

后端 未结 4 1016
Happy的楠姐
Happy的楠姐 2020-12-19 03:24

For some time, Android Studio doesn\'t show me stacktrace when developed application crashes. All I can see is following line:

06-09 16:12:36.875  26037-2603         


        
4条回答
  •  一整个雨季
    2020-12-19 03:43

    Elaborating on Radim's answer, logcat doesn't show exceptions that are handled by the setDefaultUncaughtExceptionHandler for the main thread.

    You probably use an analytics library that registers itself as the default UncaughtExceptionHandler.

    Note that, this doesn't only apply to uncaught exceptions, but also to exceptions that you log with android.util.Log. Code like this should log an exception, but will only show the "Failed" message:

    try {
      something();
    } catch (Exception e) {
      Log.v(LOG_TAG, "Failed", e);
    }
    

    Logcat will show this, with no stack trace, regardless of whether you use Log.w, Log.e, etc.

    V/MyApp: Failed
    

    Radim called out play-services-analytics as a common culprit, but Google's new analytics library is firebase-core; it has the same problem. I fixed it by disabling analytics collection on debug builds.

    I changed this line:

    FirebaseAnalytics.getInstance(this);
    

    to this:

    FirebaseAnalytics.getInstance(this).setAnalyticsCollectionEnabled(!BuildConfig.DEBUG);
    

    Thus, when I run debug builds in development, Firebase analytics doesn't handle exceptions, and I can see them in logcat.

提交回复
热议问题