如何获取Android崩溃日志?

184

我有一个应用程序,它没有在市场上(使用调试证书签名),但是我想在我的应用程序崩溃时获取崩溃日志数据。我在哪里可以找到关于应用程序崩溃原因的日志?

17个回答

3

1)通过USB插入手机(开启开发人员调试选项)

2)打开终端并导航到您的Android SDK目录(对于Mac):

cd ~/Library/Android/sdk/platform-tools

3)从该目录记录Logcat(在您的终端中)以生成日志流(对于Mac):

./adb logcat

4)打开崩溃的应用程序以生成崩溃日志

5)按Ctrl+C停止终端并查找与崩溃应用相关的日志。可能会显示类似以下内容:

AndroidRuntime:FATAL EXCEPTION: main


3

使用Acra崩溃报告器来处理Android应用程序的崩溃。Acra库


3

你使用的Java类是什么,可以获取设备的崩溃日志? - Xenolion
Thread.UncaughtExceptionHandler接口用于捕获所有未处理的崩溃。以下是相应实现的链接:https://github.com/MindorksOpenSource/CrashReporter/blob/master/crashreporter/src/main/java/com/balsikandar/crashreporter/utils/CrashReporterExceptionHandler.java。 - Bali
好的,让我来检查一下...!谢谢。 - Xenolion

1

0

如果您只是想在手机连接到电脑时查看崩溃日志,请使用Eclipse中的DDMS视图,当您的应用程序在调试过程中崩溃时,报告就在DDMS中的LogCat中。


0

基于此POST,使用此类替换"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) {
}

}

.....

在同一个Java类文件(Activity)中 ......
Public class MainActivity.....

.....

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Thread.setDefaultUncaughtExceptionHandler(new TopExceptionHandler(this));

.....


-1

尝试使用 Android 上的崩溃日志应用。

使用 链接 下载应用程序。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接