【问题标题】:Android: How to get information about caught exceptions in Google Play Developer Console?Android:如何在 Google Play Developer Console 中获取有关捕获的异常的信息?
【发布时间】:2018-06-08 23:00:02
【问题描述】:

当部署在 Google Play 商店中的应用崩溃时,您会看到这些崩溃报告。假设我有异常被Log.e 捕获和记录,有没有办法以任何方式查看这些异常?换句话说:当我想查看对我的工作流程真正重要的错误时,在 Google Play 开发者控制台中查看这些异常以在应用程序内抛出 RuntimeException 以故意使应用程序崩溃的唯一方法是什么? (那真是太愚蠢了)。

背景:我目前正在实施应用内结算。在购买过程中确实有很多阶段可能发生异常。如果客户与我联系并询问购买流程为何不起作用,我怎么知道我在 Google Play 开发者控制台中没有看到任何信息?

【问题讨论】:

标签: android google-play in-app-purchase in-app-billing


【解决方案1】:

从技术上讲,您可以使用 Crashlytics 或 HockeyApp,但它可能对您没有帮助,因为它只会在应用崩溃时触发。我的意思是这很好,但问题是如果用户有问题并且应用程序没有崩溃(购买过程没有完成)。您可以通过以下方式处理此问题(我在我的应用程序中实现了此方法):

  • 在用户设备上创建一个日志文件(注意它需要权限才能写入存储)

  • 将该日志发送到您的电子邮件地址,它将包含每个 log.e、log.d、log.it 等,它将帮助您重现错误

代码:

  public static void sendLog(Context context) {
    //set a file
    Date datum = new Date();
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
    String fullName = df.format(datum) + "appLog.txt";
    File file = new File(Environment.getExternalStorageDirectory(), fullName);

    //clears a previous log
    if (file.exists()) {
        file.delete();
    }
    //write log to file
    int pid = android.os.Process.myPid();
    try {
        String command = String.format("logcat -d -v threadtime *:*");
        Process process = Runtime.getRuntime().exec(command);

        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        StringBuilder result = new StringBuilder();
        String currentLine = null;
        while ((currentLine = reader.readLine()) != null) {
            if (currentLine != null && currentLine.contains(String.valueOf(pid))) {
                result.append(currentLine);
                result.append("\n");
            }
        }
        FileWriter out = new FileWriter(file);
        out.write(result.toString());
        out.close();
        sendEmail(context, file);
    } catch (IOException e) {
        e.printStackTrace();
    }


    //clear the log

    try {
        Runtime.getRuntime().exec("logcat -c");
    } catch (IOException e) {
        e.printStackTrace();
    }


}

将文件发送到电子邮件:

private static void sendEmail(Context context, File file) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"XXXXXXXXXX ENTER EMAIL"});
    intent.putExtra(Intent.EXTRA_SUBJECT, "Log Report");
    intent.putExtra(Intent.EXTRA_TEXT, "Add description:");
    if (!file.exists() || !file.canRead()) {
        Toast.makeText(context, "Attachment Error", Toast.LENGTH_SHORT).show();
        return;
    }
    Uri uri = Uri.parse("file://" + file);
    intent.putExtra(Intent.EXTRA_STREAM, uri);
    context.startActivity(Intent.createChooser(intent, "Send email..."));
}

【讨论】:

  • 这是一个可能的解决方案。我会考虑的(或类似的解决方案)
【解决方案2】:

您可以使用 Fire base 崩溃报告服务。我附上了 codelabs 示例代码(官方文档)。 sample code

【讨论】:

  • 这基本上回答了我的问题,但我对它不是 100% 有信心,因为我宁愿不使用比需要更多的 Google 服务。
【解决方案3】:

您可以使用Firebase Crashlytics

Firebase Crashlytics 是一款轻量级的实时崩溃报告工具,可帮助您跟踪、确定优先级并修复影响应用质量的稳定性问题。 Crashlytics 通过智能地对崩溃进行分组并突出显示导致崩溃的情况,为您节省故障排除时间。

关键能力

  • 精心策划的崩溃报告

    Crashlytics 将大量崩溃合成为一个可管理的问题列表,提供上下文信息,并突出崩溃的严重性和普遍性,以便您更快地查明根本原因。

  • 增强的环境信息

    Crashlytics 允许您按操作系统、版本、硬件配置等过滤报告。了解您的应用在特定制造商的设备、特定 API 版本,甚至在特定屏幕方向上是否更频繁地崩溃。

  • 实时提醒

    获取有关可能需要立即关注的新问题、退化问题和日益严重的问题的实时警报。

Get started with Firebase Crashlytics

【讨论】:

  • 正如 Spirit 的回答中提到的,Firebase 只预处理已经发生的崩溃,对吗?此外,它不会在 Google Play Developer 控制台中显示崩溃报告,而是在 Firebase 控制台中显示。而且我不希望我的应用程序中的 Google 依赖项超出需要。 Google 服务越多,问题就越多。
  • 尽管如此,它基本上回答了这个问题,所以我现在赞成它。 (但也许还有其他解决方案)
猜你喜欢
  • 2012-06-22
  • 2017-10-22
  • 1970-01-01
  • 2012-11-28
  • 2016-04-23
  • 2017-06-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多