I have an app that is not in the market place (signed with a debug certificate), but would like to get crash log data, whenever my application crashes. Where can I find a log of why my app crashed?
I have an app that is not in the market place (signed with a debug certificate), but would like to get crash log data, whenever my application crashes. Where can I find a log of why my app crashed?
You can try this from the console:
adb logcat --buffer=crash
More info on this option:
adb logcat --help
...
-b <buffer>, --buffer=<buffer> Request alternate ring buffer, 'main',
'system', 'radio', 'events', 'crash', 'default' or 'all'.
Multiple -b parameters or comma separated list of buffers are
allowed. Buffers interleaved. Default -b main,system,crash.
Here is a solution that can help you dump all the logs onto a text file
adb logcat -d > logs.txt
1) Plug in Phone through USB (w/ Developer Debugging options enabled)
2) Open Terminal and Navigate to your Android SDK (for Mac):
cd ~/Library/Android/sdk/platform-tools
3) Logcat from that directory (in your terminal) to generate a constant flow of logs (for Mac):
./adb logcat
4) Open your app that crashes to generate crash logs
5) Ctrl+C to stop terminal and look for the logs associated with the app that crashes. It may say something like the following:
AndroidRuntime: FATAL EXCEPTION: main
Base on this POST, use this class as replacement of "TopExceptionHandler"
class TopExceptionHandler implements Thread.UncaughtExceptionHandler {
private Thread.UncaughtExceptionHandler defaultUEH;
private Activity app = null;
private String line;
public TopExceptionHandler(Activity app) {
this.defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
this.app = app;
}
public void uncaughtException(Thread t, Throwable e) {
StackTraceElement[] arr = e.getStackTrace();
String report = e.toString()+"\n\n";
report += "--------- Stack trace ---------\n\n";
for (int i=0; i<arr.length; i++) {
report += " "+arr[i].toString()+"\n";
}
report += "-------------------------------\n\n";
// If the exception was thrown in a background thread inside
// AsyncTask, then the actual exception can be found with getCause
report += "--------- Cause ---------\n\n";
Throwable cause = e.getCause();
if(cause != null) {
report += cause.toString() + "\n\n";
arr = cause.getStackTrace();
for (int i=0; i<arr.length; i++) {
report += " "+arr[i].toString()+"\n";
}
}
report += "-------------------------------\n\n";
try {
FileOutputStream trace = app.openFileOutput("stack.trace",
Context.MODE_PRIVATE);
trace.write(report.getBytes());
trace.close();
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"kevineyni@gmail.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "crash report azar");
String body = "Mail this to kevineyni@gmail.com: " + "\n" + trace + "\n";
i.putExtra(Intent.EXTRA_TEXT , body);
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
// Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
// ReaderScopeActivity.this.startActivity(Intent.createChooser(sendIntent, "Title:"));
//ReaderScopeActivity.this.deleteFile("stack.trace");
} catch(IOException ioe) {
// ...
}
defaultUEH.uncaughtException(t, e);
}
private void startActivity(Intent chooser) {
}
}
.....
in same java class file (Activity) .....
Public class MainActivity.....
.....
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Thread.setDefaultUncaughtExceptionHandler(new TopExceptionHandler(this));
.....