I am developing an android app. My app gets crashed often. I want to save the logcat messages in sd card while the apps gets crashed to find the root cause. Is ther any way to do this?
-
Is this just for local debugging, or do you want something that can be shipped with the app? – leander May 05 '13 at 15:13
-
You may be interested in http://stackoverflow.com/questions/3378550/android-crash-reporting-library-pre-froyo and also take a look around at ACRA and other solutions. If you need to ship it you will need a pretty scary "read sensitive log data" permission. – leander May 05 '13 at 15:14
-
I need it for local debugging – vignesh May 05 '13 at 15:20
2 Answers
A few ideas which might help you step toward fully automated crash log gathering. We have yet to roll a full system here, we've had enough luck with just grabbing devices after they've crashed or asking for more info from our QA group, but:
- ACRA is relatively easy to implement, and even if you don't implement it, the source is on github for you to poke around in.
- The related question Android crash reporting library (pre Froyo) has a number of links and solutions, including android-remote-stacktrace, the aforementioned ACRA, Android-Error-Reporter, and other commercial solutions.
- Some devices capture the crash output automatically, you can grab it via
adb pull /data/log/dumpstate_app_native.txt.gz
or similar -- the paths should appear in logcat. These tend to be overwritten with each crash, though. (If anyone can answer whether this is a manufacturer-specific feature or something that appeared in some version of android's core, I'd love to know!) - You can get a logcat app, e.g. aLogCat or many others, that you can install on your device.
- TestFlight is going into beta on Android side; they have crash reporting on the iOS side and should on the Android side too, and there are various other lovely benefits to using their services -- and integration is really easy in our experience.
If you're rolling your own inside your app, you need the READ_LOGS and WRITE_EXTERNAL_STORAGE manifest permissions (even for local builds), then you can use the logging API or a regular File.copy or even a system call off to logcat
itself. There are a bunch of options and examples in the "Related" links to the side of this question:
- Stream android logcat output to an sd card
- How to redirect my log output from logcat to the SD-Card on an android device?
- ...and so on.
Hopefully this helped.
Reading your own logcat messages is covered by other questions.
how can i access logcat file on device Read logcat programmatically within application
In order to do this when your app crashes you need to install an defaultUncaughtExceptionHandler.
Either on your activity on create or your application on create. Add the following code.
final Thread.UncaughtExceptionHandler oldUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable throwable) {
// DO your error handling here.
// Write your log cat, or write your exception stack trace here.
// Get rid of this line if you don't want a popup letting you know that your app has crashed.
oldUncaughtExceptionHandler.uncaughtException(thread,throwable);
}
});

- 1
- 1

- 918
- 9
- 11