简体   繁体   English

如何让 Android 和 iOS 的 Flutter App 崩溃(测试 Firebase Crashlytics)?

[英]How to crash Flutter App for Android and iOS (to test Firebase Crashlytics)?

I want to test out crash report using Firebase Crashlytics in my Flutter App.我想在我的Flutter应用程序中使用Firebase Crashlytics测试崩溃报告。 I need to Fatal crash my flutter app for both Android and iOS programmatically.我需要以编程方式使 Android 和 iOS 的flutter应用程序致命崩溃。 Any idea?任何的想法?

You should be able to throw a Dart exception by doing this anywhere in your Flutter app:通过在 Flutter 应用程序的任何位置执行此操作,您应该能够抛出 Dart 异常:

throw Exception("This is a crash!");

Or by using an arbitrary object:或者通过使用任意对象:

throw "This is a crash!";

You can find more info about dart exceptions in the language tour and if you want, you can create your own custom Exception type as explained in this SO answer您可以在语言导览中找到有关 dart 异常的更多信息,如果需要,您可以创建自己的自定义异常类型, 如此 SO 答案中所述

如果你有flutter_crashlytics插件,你可以使用

FirebaseCrashlytics.instance.crash();

集成firebase_crashlytics

 Crashlytics.instance.crash();

using firebase_crashlytics plugin使用 firebase_crashlytics 插件

FirebaseCrashlytics.instance.crash();

You should enable crashlytics您应该启用 crashlytics

void main() async{
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  if (kDebugMode) {
    FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);//disable false
  }else{
    FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);
  }

Divide by zero. 除以零。 Parse wrong data wrong way (ie float string as int). 以错误的方式解析错误的数据(即,将浮点字符串转换为int)。 Throw uncaught exception. 引发未捕获的异常。 Access things you got no permissions for. 访问您没有权限的内容。 And so on. 等等。 Be creative 有创造力

Try to add any value without initializing the list.尝试在不初始化列表的情况下添加任何值。 there will be an app crash and give this error The method 'add' was called on null.将会有一个应用程序崩溃并给出这个错误The method 'add' was called on null.

List list;

list.add("add");

You can crash you Flutter app by many ways:您可以通过多种方式使 Flutter 应用程序崩溃:

  1. throw(Exception('Hello Crashlytics')); like in @Xavi Rigau's answer就像@Xavi Rigau 的回答一样
List list;

list.add("add");

Like @Paresh Mangukiya does.就像@Paresh Mangukiya 那样。

3. 3.

final a = [12];
print(a[1]);

But there is 2 IMPORTANT thing you should consider:但是您应该考虑两件重要的事情:

  • You should run your app in release mode, for example with the command flutter run --release您应该在发布模式下运行您的应用程序,例如使用命令flutter run --release
  • In Crashlytycs console, by default shown only fatal crashes.在 Crashlytycs 控制台中,默认情况下仅显示致命崩溃。 The crashes above are non-fatal crashes.上面的崩溃是非致命的崩溃。 So, you should clear the filter to see all crash types.因此,您应该清除过滤器以查看所有崩溃类型。 (Filter can be filtered in crashlytics dashboard by clicking (x) button near filter). (可以通过单击过滤器附近的 (x) 按钮在 crashlytics 仪表板中过滤过滤器)。 More on this you can read from this SO answer您可以从这个 SO answer 中阅读更多关于此的信息

Check this out .看一下这个 。 This is from the official documentation.这是来自官方文档。 https://firebase.flutter.dev/docs/crashlytics/usage https://firebase.flutter.dev/docs/crashlytics/usage

Once your configuration is proper according to documentation for crashlytics, FirebaseCrashlytics.instance.crash();根据 crashlytics 的文档 FirebaseCrashlytics.instance.crash(); 一旦您的配置正确; will crash the app.会使应用程序崩溃。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM