最近小编在开发flutter应用时出现了“Could not prepare to run the isolate”错误,具体错误内容如下:
D/FlutterActivityAndFragmentDelegate( 4887): No preferred FlutterEngine was provided. Creating a new FlutterEngine for this FlutterFragment. D/FlutterActivityAndFragmentDelegate( 4887): Attaching FlutterEngine to the Activity t hat owns this Fragment. D/FlutterView( 4887): Attaching to a FlutterEngine: io.flutter.embedding.engine.Flutte rEngine@faa0146 D/FlutterActivityAndFragmentDelegate( 4887): Executing Dart entrypoint: main, and send ing initial route: / E/flutter ( 4887): [ERROR:flutter/shell/common/shell.cc(199)] Dart Error: error: impor t of dart:mirrors is not supported in the current Dart runtime E/flutter ( 4887): [ERROR:flutter/shell/common/engine.cc(198)] Could not prepare to ru n the isolate. E/flutter ( 4887): [ERROR:flutter/shell/common/engine.cc(137)] Engine not prepare and launch isolate. E/flutter ( 4887): [ERROR:flutter/shell/common/shell.cc(437)] Could not launch engine with configuration. |
解决方案:
小编也刚开始不知道“Could not prepare to run the isolate”的错误原因,最后排查,发现是“import”倒包的问题,也许是和系统有冲突,所以小编找了很久,将一个可疑的dart导包给去掉就好了,如下:
//import 'package:json_serializable/json_serializable.dart'; //注释掉可疑的package //@JsonSerializableGenerator() class News { final int id; String title; String author; String updateDate; String photourlOne; News(this.id, this.title, this.author, this.updateDate, this.photourlOne); }
当然了,小编引入的json转换工具也有问题(主要是小编不会用),所以把pubspec.yaml里面的“json_serializable”包一并去掉了。
json_serializable: ^3.2.5
提示:
出现“Could not prepare to run the isolate”的问题基本都是导包的问题,可能是有冲突,也可能自己用错了,总之解决的重点是排查导包问题。