【问题标题】:Save android exception to file将android异常保存到文件
【发布时间】:2020-02-08 16:27:58
【问题描述】:

我的设备调试能力很差,而且它在车内,无法连接到 PC。我的程序可以在 3 个不同的模拟器和我的个人手机上运行。但在汽车中它有时会崩溃(如异常)。我不知道它发生在程序的哪个位置,所以我不能只做try...catch 并保存 printStackError。但我想保存导致程序终止到 txt 文件的异常。

所有已建立的答案都转到try...catch 这不是一个选项。

Android 是否有类似 onCrash 或类似的东西。

更新 1:

我不能使用 Google play 或 google-services,因为它是独立的应用程序,没有设备上的 Google play。

【问题讨论】:

标签: android exception


【解决方案1】:

您可以在项目中使用 Firebase Crashlytics。它会将崩溃日志发送到您的 firebase 项目窗口中的 Crashlytics 页面

第 1 步

在您的项目级 build.gradle 中,将您的 google-services 更新为 版本 3.1.2 或更高版本,然后添加 Crashlytics 存储库和 依赖:

buildscript {
    repositories {
        // Add the following repositories:
        google()  // Google's Maven repository

        maven {
           url 'https://maven.fabric.io/public'
        }
    }

    dependencies {
        // ...

        // Check for v3.1.2 or higher
        classpath 'com.google.gms:google-services:4.3.2'  // Google Services plugin

        // Add dependency
        classpath 'io.fabric.tools:gradle:1.31.1'  // Crashlytics plugin


    }
}


allprojects {
    // ...

    repositories {
       // Check that you have the following line (if not, add it):
       google()  // Google's Maven repository
       // ...
    }
}

第 2 步

在您的应用级 build.gradle 中,添加 Crashlytics 依赖:

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

dependencies {
    // ...

    // (Recommended) Add Analytics
    implementation 'com.google.firebase:firebase-analytics:17.2.0'

    // Add dependency
    implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
}

Here's Firebase Crashlytics 的完整文档

【讨论】:

  • 是的,这是一个很好的解决方案。我只是忘了说,我不能使用 google-play 或服务。这是一个独立的设备。
猜你喜欢
  • 2010-12-15
  • 2019-07-28
  • 2013-08-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-20
  • 2015-04-30
  • 1970-01-01
相关资源
最近更新 更多