fac*_*omr 72 android firebase firebase-crash-reporting
我已成功实施Firebase崩溃报告,但我需要在应用程序运行时禁用该服务撤消'debug'Build Variant,以避免在开发期间控制台中出现非真实崩溃.
官方文档没有说明这一点.
Woo*_*gie 47
更新:使用Google Play Services/Firebase 11+,您现在可以在运行时禁用崩溃报告.FirebaseCrash.setCrashCollectionEnabled()(谢谢@Tyler Carberry)
老答案:
就社区已经猜测而言,没有官方支持.我建议这样做的最佳方式是,在信息中心设置多个Firebase应用,每个版本类型一个,并根据构建版本设置多个指向每个不同应用的google_services.json文件.
Tyl*_*rry 30
使用Google Play Services 11.0,您现在可以在运行时禁用崩溃报告.
FirebaseCrash.setCrashCollectionEnabled(!BuildConfig.DEBUG);
Run Code Online (Sandbox Code Playgroud)
evi*_*evi 23
最近有人介绍了以官方方式禁用Firebase崩溃报告的可能性.您需要将firebase android sdk升级到至少版本11.0.0
为此,您需要编辑AndroidManifest.xml并添加:
<meta-data
android:name="firebase_crash_collection_enabled"
android:value="false" />
Run Code Online (Sandbox Code Playgroud)
在<application>街区内.
您可以使用FirebaseCrash.isCrashCollectionEnabled()检查运行时是否启用了Firebase崩溃报告.
下面是一个完整示例,用于在调试版本中禁用Firebase崩溃报告.
build.gradle:
...
buildTypes {
release {
...
resValue("bool", "FIREBASE_CRASH_ENABLED", "true")
}
debug {
...
resValue("bool", "FIREBASE_CRASH_ENABLED", "false")
}
}
...
dependencies {
...
compile "com.google.firebase:firebase-core:11.0.0"
compile "com.google.firebase:firebase-crash:11.0.0"
...
}
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml:
<application>
<meta-data
android:name="firebase_crash_collection_enabled"
android:value="@bool/FIREBASE_CRASH_ENABLED"/>
...
Run Code Online (Sandbox Code Playgroud)
Mar*_*arc 11
在我的Application类中,onCreate()
if (BuildConfig.DEBUG) {
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread paramThread, Throwable paramThrowable) {
Log.wtf("Alert", paramThrowable.getMessage(), paramThrowable);
System.exit(2); //Prevents the service/app from freezing
}
});
}
Run Code Online (Sandbox Code Playgroud)
它的工作原理是它需要oldHandler,其中包括Firebase
final UncaughtExceptionHandler oldHandler = Thread.getDefaultUncaughtExceptionHandler();
Run Code Online (Sandbox Code Playgroud)
走出处理路径
Mar*_*ren 11
您可以将firebase崩溃依赖项更改为仅发布依赖项.
为此,您将其定义为releaseCompile依赖项
releaseCompile 'com.google.firebase:firebase-crash:9.4.0'
Run Code Online (Sandbox Code Playgroud)
现在它只会包含在发布版本中.如果您有其他想要崩溃报告的自定义构建类型,则可以将其添加到其中.
customBuildTypeCompile 'com.google.firebase:firebase-crash:9.4.0'
Run Code Online (Sandbox Code Playgroud)
我使用的简单易用的技巧是仅在build.gradle文件中的发布版本中添加firebase崩溃报告依赖项.
这将从调试构建类型中删除崩溃报告库,并仅在发布版本中添加它.
dependencies {
releaseCompile 'com.google.firebase:firebase-crash:10.2.0'
}
Run Code Online (Sandbox Code Playgroud)
受到这个相关答案和其他人的启发,我想出了这个方便的解决方案.
使用Timber进行日志记录,我为调试和发布版本创建了Tree子类的不同实现.在调试中,它遵循写入logcat的DebugTree.在发布中,它将异常和高优先级日志转发给Firebase,其余部分则丢弃.
的build.gradle
dependencies {
...
compile 'com.jakewharton.timber:timber:4.3.0'
releaseCompile 'com.google.firebase:firebase-crash:9.0.2'
}
Run Code Online (Sandbox Code Playgroud)
SRC /调试/ JAVA/[包] /ForestFire.java
import timber.log.Timber;
public class ForestFire extends Timber.DebugTree {}
Run Code Online (Sandbox Code Playgroud)
的src /释放/ JAVA/[包] /ForestFire.java
import android.util.Log;
import com.google.firebase.crash.FirebaseCrash;
import timber.log.Timber;
public class ForestFire extends Timber.Tree {
@Override
protected void log(int priority, String tag, String message, Throwable t) {
if (Log.WARN <= priority) {
FirebaseCrash.log(message);
if (t != null) {
FirebaseCrash.report(t);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
App启动
Timber.plant(new ForestFire());
Run Code Online (Sandbox Code Playgroud)
首先初始化gradle文件中的变量,并检查它是处于调试模式还是处于释放模式.提交崩溃报告的最佳方法是在Application类中.
的build.gradle
buildTypes {
release {
buildConfigField "Boolean", "REPORT_CRASH", '"true"'
debuggable false
}
debug {
buildConfigField "Boolean", "REPORT_CRASH", '"false"'
debuggable true
}
}
Run Code Online (Sandbox Code Playgroud)
现在首先检查模式并在崩溃时提交崩溃报告.
Application.java
/** Report FirebaseCrash Exception if application crashed*/
Thread.setDefaultUncaughtExceptionHandler (new Thread.UncaughtExceptionHandler()
{
@Override
public void uncaughtException (Thread thread, Throwable e)
{
/** Check whether it is development or release mode*/
if(BuildConfig.REPORT_CRASH)
{
FirebaseCrash.report( e);
}
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18957 次 |
| 最近记录: |