[英]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();
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 应用程序崩溃:
throw(Exception('Hello Crashlytics'));
like in @Xavi Rigau's answerList 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:但是您应该考虑两件重要的事情:
flutter run --release
flutter run --release
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.