How do I obtain crash-data from my Android application?

前端 未结 30 2496
庸人自扰
庸人自扰 2020-11-22 01:10

How can I get crash data (stack traces at least) from my Android application? At least when working on my own device being retrieved by cable, but ideally from any instance

相关标签:
30条回答
  • 2020-11-22 01:30

    This is very brute, but it is possible to run logcat anywhere, so a quick and dirty hack is to add to any catch block getRuntime().exec("logcat >> /sdcard/logcat.log");

    0 讨论(0)
  • 2020-11-22 01:31

    Ok, well I looked at the provided samples from rrainn and Soonil, and I found a solution that does not mess up error handling.

    I modified the CustomExceptionHandler so it stores the original UncaughtExceptionHandler from the Thread we associate the new one. At the end of the new "uncaughtException"- Method I just call the old function using the stored UncaughtExceptionHandler.

    In the DefaultExceptionHandler class you need sth. like this:

    public class DefaultExceptionHandler implements UncaughtExceptionHandler{
      private UncaughtExceptionHandler mDefaultExceptionHandler;
    
      //constructor
      public DefaultExceptionHandler(UncaughtExceptionHandler pDefaultExceptionHandler)
      {
           mDefaultExceptionHandler= pDefaultExceptionHandler;
      }
      public void uncaughtException(Thread t, Throwable e) {       
            //do some action like writing to file or upload somewhere         
    
            //call original handler  
            mStandardEH.uncaughtException(t, e);        
    
            // cleanup, don't know if really required
            t.getThreadGroup().destroy();
      }
    }
    

    With that modification on the code at http://code.google.com/p/android-remote-stacktrace you have a good working base for logging in the field to your webserver or to sd-card.

    0 讨论(0)
  • 2020-11-22 01:32

    For an alternate crash reporting/exception tracking service check out Raygun.io - it's got a bunch of nice logic for handling Android crashes, including decent user experience when plugging it in to your app (two lines of code in your main Activity and a few lines of XML pasted into AndroidManifest).

    When your app crashes, it'll automatically grab the stack trace, environment data for hard/software, user tracking info, any custom data you specify etc. It posts it to the API asynchronously so no blocking of the UI thread, and caches it to disk if there's no network available.

    Disclaimer: I built the Android provider :)

    0 讨论(0)
  • 2020-11-22 01:33

    I found one more great web application to track the error reports.

    https://mint.splunk.com/

    Small number of steps to configure.

    1. Login or sign up and configure using the above link. Once you done creating a application they will provide a line to configure like below.
    Mint.initAndStartSession(YourActivity.this, "api_key");
    
    1. Add the following in the application's build.gradl.
    android {
    ...
        repositories {
            maven { url "https://mint.splunk.com/gradle/"}
        }
    ...
    }
    
    dependencies {
    ...
        compile "com.splunk.mint:mint:4.4.0"
    ...
    }
    
    1. Add the code which we copied above and add it to every activity.

      Mint.initAndStartSession(YourActivity.this, "api_key");

    That's it. You login and go to you application dashboard, you will get all the error reports.

    Hope it helps someone.

    0 讨论(0)
  • 2020-11-22 01:34

    use this to catch the exception details:

    String stackTrace = Log.getStackTraceString(exception); 
    

    store this in database and maintain the log.

    0 讨论(0)
  • 2020-11-22 01:34

    There is a tool called fabric, this is a crash analytic tool, which will allow you to get crash reports , when application deployed live and during development. Adding this tool to your application was simple as well.. When your application crash that report of the crash can be viewed from your fabric.io dashboard . thw report was catched automatically.it won't ask user for permission. Whether he/she want to send the bug/crash report. And this is completely free... https://get.fabric.io/

    0 讨论(0)
提交回复
热议问题