Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio missing exception stacktrace in Logcat

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-26037/com.a.b W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x4206c700)

This drives me crazy because I cannot see, where application really crashed (and what exception occurs). I'm using AS 1.3 Preview 2. At first I though there is problem with dependencies, but now I'm using just these and problem still occurs:

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  compile 'com.android.support:appcompat-v7:22.2.0'
  compile 'com.google.android.gms:play-services-base:7.5.0'
  compile 'com.google.android.gms:play-services-analytics:7.5.0'
  compile 'com.jakewharton:butterknife:6.1.0'
}

Problem is probably based on fact that application doesn't crash, but only freeze.

Thanks for every suggestion.

like image 654
skywall Avatar asked Jun 09 '15 14:06

skywall


People also ask

What is exception Stacktrace?

A trace of the method calls is called a stack trace. The stack trace listing provides a way to follow the call stack to the line number in the method where the exception occurs. The StackTrace property returns the frames of the call stack that originate at the location where the exception was thrown.

Should Stacktrace be logged?

Therefore, you should log a stacktrace if, and only if, and always if, the exception indicates a bug in the program. However, that does not always indicate that a method you write should catch and log the exception.


1 Answers

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.

like image 124
Dan Fabulich Avatar answered Nov 16 '22 04:11

Dan Fabulich